blob: 8f404dc4211e6ca38b90086e19f4fd48e44d7ede [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===------------------------------ vector --------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_VECTOR
12#define _LIBCPP_VECTOR
13
14/*
15 vector synopsis
16
17namespace std
18{
19
Howard Hinnant324bb032010-08-22 00:02:4320template <class T, class Allocator = allocator<T> >
Howard Hinnantbc8d3f92010-05-11 19:42:1621class vector
Howard Hinnant324bb032010-08-22 00:02:4322{
23public:
24 typedef T value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:1625 typedef Allocator allocator_type;
26 typedef typename allocator_type::reference reference;
27 typedef typename allocator_type::const_reference const_reference;
28 typedef implementation-defined iterator;
29 typedef implementation-defined const_iterator;
30 typedef typename allocator_type::size_type size_type;
31 typedef typename allocator_type::difference_type difference_type;
32 typedef typename allocator_type::pointer pointer;
33 typedef typename allocator_type::const_pointer const_pointer;
34 typedef std::reverse_iterator<iterator> reverse_iterator;
35 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
36
Howard Hinnantd1d27a42011-06-03 19:40:4037 vector()
38 noexcept(is_nothrow_default_constructible<allocator_type>::value);
39 explicit vector(const allocator_type&);
Howard Hinnantbc8d3f92010-05-11 19:42:1640 explicit vector(size_type n);
Marshall Clowa49a2c92013-09-14 00:47:5941 explicit vector(size_type n, const allocator_type&); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1642 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
43 template <class InputIterator>
44 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
45 vector(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:4046 vector(vector&& x)
47 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1648 vector(initializer_list<value_type> il);
49 vector(initializer_list<value_type> il, const allocator_type& a);
50 ~vector();
51 vector& operator=(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:4052 vector& operator=(vector&& x)
53 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:0054 allocator_type::propagate_on_container_move_assignment::value ||
55 allocator_type::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:1656 vector& operator=(initializer_list<value_type> il);
57 template <class InputIterator>
58 void assign(InputIterator first, InputIterator last);
59 void assign(size_type n, const value_type& u);
60 void assign(initializer_list<value_type> il);
61
Howard Hinnantd1d27a42011-06-03 19:40:4062 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1663
Howard Hinnantd1d27a42011-06-03 19:40:4064 iterator begin() noexcept;
65 const_iterator begin() const noexcept;
66 iterator end() noexcept;
67 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1668
Howard Hinnantd1d27a42011-06-03 19:40:4069 reverse_iterator rbegin() noexcept;
70 const_reverse_iterator rbegin() const noexcept;
71 reverse_iterator rend() noexcept;
72 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1673
Howard Hinnantd1d27a42011-06-03 19:40:4074 const_iterator cbegin() const noexcept;
75 const_iterator cend() const noexcept;
76 const_reverse_iterator crbegin() const noexcept;
77 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1678
Howard Hinnantd1d27a42011-06-03 19:40:4079 size_type size() const noexcept;
80 size_type max_size() const noexcept;
81 size_type capacity() const noexcept;
82 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1683 void reserve(size_type n);
Howard Hinnantd1d27a42011-06-03 19:40:4084 void shrink_to_fit() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1685
86 reference operator[](size_type n);
87 const_reference operator[](size_type n) const;
88 reference at(size_type n);
89 const_reference at(size_type n) const;
90
91 reference front();
92 const_reference front() const;
93 reference back();
94 const_reference back() const;
95
Howard Hinnantd1d27a42011-06-03 19:40:4096 value_type* data() noexcept;
97 const value_type* data() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1698
99 void push_back(const value_type& x);
100 void push_back(value_type&& x);
101 template <class... Args>
Marshall Clow4e42dc92017-01-24 23:09:12102 reference emplace_back(Args&&... args); // reference in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16103 void pop_back();
104
105 template <class... Args> iterator emplace(const_iterator position, Args&&... args);
106 iterator insert(const_iterator position, const value_type& x);
107 iterator insert(const_iterator position, value_type&& x);
108 iterator insert(const_iterator position, size_type n, const value_type& x);
109 template <class InputIterator>
110 iterator insert(const_iterator position, InputIterator first, InputIterator last);
111 iterator insert(const_iterator position, initializer_list<value_type> il);
112
113 iterator erase(const_iterator position);
114 iterator erase(const_iterator first, const_iterator last);
115
Howard Hinnantd1d27a42011-06-03 19:40:40116 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16117
118 void resize(size_type sz);
119 void resize(size_type sz, const value_type& c);
120
Howard Hinnantd1d27a42011-06-03 19:40:40121 void swap(vector&)
Marshall Clow7d914d12015-07-13 20:04:56122 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
123 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16124
125 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43126};
Howard Hinnantbc8d3f92010-05-11 19:42:16127
Howard Hinnant324bb032010-08-22 00:02:43128template <class Allocator = allocator<T> >
Howard Hinnantbc8d3f92010-05-11 19:42:16129class vector<bool, Allocator>
Howard Hinnant324bb032010-08-22 00:02:43130{
131public:
132 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16133 typedef Allocator allocator_type;
134 typedef implementation-defined iterator;
135 typedef implementation-defined const_iterator;
136 typedef typename allocator_type::size_type size_type;
137 typedef typename allocator_type::difference_type difference_type;
138 typedef iterator pointer;
139 typedef const_iterator const_pointer;
140 typedef std::reverse_iterator<iterator> reverse_iterator;
141 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
142
143 class reference
144 {
145 public:
Howard Hinnantd1d27a42011-06-03 19:40:40146 reference(const reference&) noexcept;
147 operator bool() const noexcept;
148 reference& operator=(const bool x) noexcept;
149 reference& operator=(const reference& x) noexcept;
150 iterator operator&() const noexcept;
151 void flip() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16152 };
153
154 class const_reference
155 {
156 public:
Howard Hinnantd1d27a42011-06-03 19:40:40157 const_reference(const reference&) noexcept;
158 operator bool() const noexcept;
159 const_iterator operator&() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16160 };
161
Howard Hinnantd1d27a42011-06-03 19:40:40162 vector()
163 noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant9cbee432011-09-02 20:42:31164 explicit vector(const allocator_type&);
Marshall Clowa49a2c92013-09-14 00:47:59165 explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
166 vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16167 template <class InputIterator>
168 vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
169 vector(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40170 vector(vector&& x)
171 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16172 vector(initializer_list<value_type> il);
173 vector(initializer_list<value_type> il, const allocator_type& a);
174 ~vector();
175 vector& operator=(const vector& x);
Howard Hinnantd1d27a42011-06-03 19:40:40176 vector& operator=(vector&& x)
177 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00178 allocator_type::propagate_on_container_move_assignment::value ||
179 allocator_type::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16180 vector& operator=(initializer_list<value_type> il);
181 template <class InputIterator>
182 void assign(InputIterator first, InputIterator last);
183 void assign(size_type n, const value_type& u);
184 void assign(initializer_list<value_type> il);
185
Howard Hinnantd1d27a42011-06-03 19:40:40186 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16187
Howard Hinnantd1d27a42011-06-03 19:40:40188 iterator begin() noexcept;
189 const_iterator begin() const noexcept;
190 iterator end() noexcept;
191 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16192
Howard Hinnantd1d27a42011-06-03 19:40:40193 reverse_iterator rbegin() noexcept;
194 const_reverse_iterator rbegin() const noexcept;
195 reverse_iterator rend() noexcept;
196 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16197
Howard Hinnantd1d27a42011-06-03 19:40:40198 const_iterator cbegin() const noexcept;
199 const_iterator cend() const noexcept;
200 const_reverse_iterator crbegin() const noexcept;
201 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16202
Howard Hinnantd1d27a42011-06-03 19:40:40203 size_type size() const noexcept;
204 size_type max_size() const noexcept;
205 size_type capacity() const noexcept;
206 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16207 void reserve(size_type n);
Howard Hinnantd1d27a42011-06-03 19:40:40208 void shrink_to_fit() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16209
210 reference operator[](size_type n);
211 const_reference operator[](size_type n) const;
212 reference at(size_type n);
213 const_reference at(size_type n) const;
214
215 reference front();
216 const_reference front() const;
217 reference back();
218 const_reference back() const;
219
220 void push_back(const value_type& x);
Marshall Clow4e42dc92017-01-24 23:09:12221 template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16222 void pop_back();
223
Marshall Clow198a2a52013-08-13 23:54:12224 template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16225 iterator insert(const_iterator position, const value_type& x);
226 iterator insert(const_iterator position, size_type n, const value_type& x);
227 template <class InputIterator>
228 iterator insert(const_iterator position, InputIterator first, InputIterator last);
229 iterator insert(const_iterator position, initializer_list<value_type> il);
230
231 iterator erase(const_iterator position);
232 iterator erase(const_iterator first, const_iterator last);
233
Howard Hinnantd1d27a42011-06-03 19:40:40234 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16235
236 void resize(size_type sz);
237 void resize(size_type sz, value_type x);
238
Howard Hinnantd1d27a42011-06-03 19:40:40239 void swap(vector&)
Marshall Clow7d914d12015-07-13 20:04:56240 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
241 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantd1d27a42011-06-03 19:40:40242 void flip() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16243
244 bool __invariants() const;
Howard Hinnant324bb032010-08-22 00:02:43245};
Howard Hinnantbc8d3f92010-05-11 19:42:16246
247template <class Allocator> struct hash<std::vector<bool, Allocator>>;
248
249template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
250template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
251template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
252template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
253template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
254template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
255
Howard Hinnantd1d27a42011-06-03 19:40:40256template <class T, class Allocator>
257void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
258 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16259
260} // std
261
262*/
263
264#include <__config>
Eric Fiselierb3792282016-02-20 00:19:45265#include <iosfwd> // for forward declaration of vector
Howard Hinnantbc8d3f92010-05-11 19:42:16266#include <__bit_reference>
267#include <type_traits>
268#include <climits>
269#include <limits>
270#include <initializer_list>
271#include <memory>
272#include <stdexcept>
273#include <algorithm>
274#include <cstring>
275#include <__split_buffer>
276#include <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16277
Howard Hinnant66c6f972011-11-29 16:45:27278#include <__undef_min_max>
279
Eric Fiselierb9536102014-08-10 23:53:08280#include <__debug>
Howard Hinnant8b00e6c2013-08-02 00:26:35281
Howard Hinnant08e17472011-10-17 20:05:10282#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16283#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10284#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16285
286_LIBCPP_BEGIN_NAMESPACE_STD
287
288template <bool>
289class __vector_base_common
290{
291protected:
292 _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
Marshall Clow14c09a22016-08-25 15:09:01293 _LIBCPP_NORETURN void __throw_length_error() const;
294 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16295};
296
297template <bool __b>
298void
299__vector_base_common<__b>::__throw_length_error() const
300{
Marshall Clow14c09a22016-08-25 15:09:01301 _VSTD::__throw_length_error("vector");
Howard Hinnantbc8d3f92010-05-11 19:42:16302}
303
304template <bool __b>
305void
306__vector_base_common<__b>::__throw_out_of_range() const
307{
Marshall Clow14c09a22016-08-25 15:09:01308 _VSTD::__throw_out_of_range("vector");
Howard Hinnantbc8d3f92010-05-11 19:42:16309}
310
Howard Hinnante9df0a52013-08-01 18:17:34311#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45312#pragma warning( push )
313#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34314#endif // _LIBCPP_MSVC
Eric Fiselier833d6442016-09-15 22:27:07315_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34316#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45317#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34318#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16319
320template <class _Tp, class _Allocator>
321class __vector_base
322 : protected __vector_base_common<true>
323{
324protected:
Howard Hinnant324bb032010-08-22 00:02:43325 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16326 typedef _Allocator allocator_type;
327 typedef allocator_traits<allocator_type> __alloc_traits;
328 typedef value_type& reference;
329 typedef const value_type& const_reference;
330 typedef typename __alloc_traits::size_type size_type;
331 typedef typename __alloc_traits::difference_type difference_type;
332 typedef typename __alloc_traits::pointer pointer;
333 typedef typename __alloc_traits::const_pointer const_pointer;
334 typedef pointer iterator;
335 typedef const_pointer const_iterator;
336
337 pointer __begin_;
338 pointer __end_;
339 __compressed_pair<pointer, allocator_type> __end_cap_;
340
Howard Hinnantd1d27a42011-06-03 19:40:40341 _LIBCPP_INLINE_VISIBILITY
342 allocator_type& __alloc() _NOEXCEPT
343 {return __end_cap_.second();}
344 _LIBCPP_INLINE_VISIBILITY
345 const allocator_type& __alloc() const _NOEXCEPT
346 {return __end_cap_.second();}
347 _LIBCPP_INLINE_VISIBILITY
348 pointer& __end_cap() _NOEXCEPT
349 {return __end_cap_.first();}
350 _LIBCPP_INLINE_VISIBILITY
351 const pointer& __end_cap() const _NOEXCEPT
352 {return __end_cap_.first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16353
Howard Hinnantd1d27a42011-06-03 19:40:40354 _LIBCPP_INLINE_VISIBILITY
355 __vector_base()
356 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43357 _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16358 ~__vector_base();
359
Howard Hinnantd1d27a42011-06-03 19:40:40360 _LIBCPP_INLINE_VISIBILITY
361 void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
362 _LIBCPP_INLINE_VISIBILITY
363 size_type capacity() const _NOEXCEPT
364 {return static_cast<size_type>(__end_cap() - __begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16365
Howard Hinnantd1d27a42011-06-03 19:40:40366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2c39cbe2013-06-27 19:35:32367 void __destruct_at_end(pointer __new_last) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16368
Howard Hinnantee6ccd02010-09-23 18:58:28369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16370 void __copy_assign_alloc(const __vector_base& __c)
371 {__copy_assign_alloc(__c, integral_constant<bool,
372 __alloc_traits::propagate_on_container_copy_assignment::value>());}
373
Howard Hinnantee6ccd02010-09-23 18:58:28374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16375 void __move_assign_alloc(__vector_base& __c)
Howard Hinnantd1d27a42011-06-03 19:40:40376 _NOEXCEPT_(
377 !__alloc_traits::propagate_on_container_move_assignment::value ||
378 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16379 {__move_assign_alloc(__c, integral_constant<bool,
380 __alloc_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16381private:
Howard Hinnantee6ccd02010-09-23 18:58:28382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16383 void __copy_assign_alloc(const __vector_base& __c, true_type)
384 {
385 if (__alloc() != __c.__alloc())
386 {
387 clear();
388 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
389 __begin_ = __end_ = __end_cap() = nullptr;
390 }
391 __alloc() = __c.__alloc();
392 }
393
Howard Hinnantee6ccd02010-09-23 18:58:28394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04395 void __copy_assign_alloc(const __vector_base&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16396 {}
397
Howard Hinnantee6ccd02010-09-23 18:58:28398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31399 void __move_assign_alloc(__vector_base& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:40400 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16401 {
Howard Hinnant0949eed2011-06-30 21:18:19402 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16403 }
404
Howard Hinnantee6ccd02010-09-23 18:58:28405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04406 void __move_assign_alloc(__vector_base&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:40407 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16408 {}
Howard Hinnantbc8d3f92010-05-11 19:42:16409};
410
411template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00412inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16413void
Howard Hinnant2c39cbe2013-06-27 19:35:32414__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16415{
Bruce Mitchener50145cc2017-03-23 14:39:23416 pointer __soon_to_be_end = __end_;
417 while (__new_last != __soon_to_be_end)
418 __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__soon_to_be_end));
419 __end_ = __new_last;
Howard Hinnantbc8d3f92010-05-11 19:42:16420}
421
422template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00423inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16424__vector_base<_Tp, _Allocator>::__vector_base()
Howard Hinnantd1d27a42011-06-03 19:40:40425 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant2c39cbe2013-06-27 19:35:32426 : __begin_(nullptr),
427 __end_(nullptr),
428 __end_cap_(nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16429{
430}
431
432template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00433inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16434__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:32435 : __begin_(nullptr),
436 __end_(nullptr),
437 __end_cap_(nullptr, __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16438{
439}
440
441template <class _Tp, class _Allocator>
442__vector_base<_Tp, _Allocator>::~__vector_base()
443{
Howard Hinnant2c39cbe2013-06-27 19:35:32444 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16445 {
446 clear();
447 __alloc_traits::deallocate(__alloc(), __begin_, capacity());
448 }
449}
450
Eric Fiselierb3792282016-02-20 00:19:45451template <class _Tp, class _Allocator /* = allocator<_Tp> */>
Eric Fiselierc3589a82017-01-04 23:56:00452class _LIBCPP_TEMPLATE_VIS vector
Howard Hinnantbc8d3f92010-05-11 19:42:16453 : private __vector_base<_Tp, _Allocator>
454{
455private:
456 typedef __vector_base<_Tp, _Allocator> __base;
Marshall Clow1f50f2d2014-05-08 14:14:06457 typedef allocator<_Tp> __default_allocator_type;
Howard Hinnant324bb032010-08-22 00:02:43458public:
Howard Hinnantbc8d3f92010-05-11 19:42:16459 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:43460 typedef _Tp value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16461 typedef _Allocator allocator_type;
462 typedef typename __base::__alloc_traits __alloc_traits;
463 typedef typename __base::reference reference;
464 typedef typename __base::const_reference const_reference;
465 typedef typename __base::size_type size_type;
466 typedef typename __base::difference_type difference_type;
467 typedef typename __base::pointer pointer;
468 typedef typename __base::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16469 typedef __wrap_iter<pointer> iterator;
470 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19471 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
472 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16473
Howard Hinnant02d5e182013-03-26 19:04:56474 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
475 "Allocator::value_type must be same type as value_type");
476
Howard Hinnantd1d27a42011-06-03 19:40:40477 _LIBCPP_INLINE_VISIBILITY
Marshall Clowc912c0c2015-06-04 02:05:41478 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant7a563db2011-09-14 18:33:51479 {
Howard Hinnantabe26282011-09-16 17:29:17480#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51481 __get_db()->__insert_c(this);
482#endif
483 }
484 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
Marshall Clow127db912015-06-04 00:10:20485#if _LIBCPP_STD_VER <= 14
486 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
487#else
488 _NOEXCEPT
489#endif
Howard Hinnant7a563db2011-09-14 18:33:51490 : __base(__a)
491 {
Howard Hinnantabe26282011-09-16 17:29:17492#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51493 __get_db()->__insert_c(this);
494#endif
495 }
Howard Hinnantbc8d3f92010-05-11 19:42:16496 explicit vector(size_type __n);
Marshall Clowa49a2c92013-09-14 00:47:59497#if _LIBCPP_STD_VER > 11
498 explicit vector(size_type __n, const allocator_type& __a);
499#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16500 vector(size_type __n, const_reference __x);
501 vector(size_type __n, const_reference __x, const allocator_type& __a);
502 template <class _InputIterator>
Howard Hinnantde589f22013-09-21 21:13:54503 vector(_InputIterator __first,
Howard Hinnantbc8d3f92010-05-11 19:42:16504 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32505 !__is_forward_iterator<_InputIterator>::value &&
506 is_constructible<
507 value_type,
Howard Hinnantde589f22013-09-21 21:13:54508 typename iterator_traits<_InputIterator>::reference>::value,
509 _InputIterator>::type __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16510 template <class _InputIterator>
511 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
512 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32513 !__is_forward_iterator<_InputIterator>::value &&
514 is_constructible<
515 value_type,
516 typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16517 template <class _ForwardIterator>
Howard Hinnantde589f22013-09-21 21:13:54518 vector(_ForwardIterator __first,
Howard Hinnant742fecb2013-03-28 17:44:32519 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
520 is_constructible<
521 value_type,
Howard Hinnantde589f22013-09-21 21:13:54522 typename iterator_traits<_ForwardIterator>::reference>::value,
523 _ForwardIterator>::type __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16524 template <class _ForwardIterator>
525 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
Howard Hinnant742fecb2013-03-28 17:44:32526 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
527 is_constructible<
528 value_type,
529 typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02530#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16532 vector(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16534 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02535#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantabe26282011-09-16 17:29:17536#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantee6ccd02010-09-23 18:58:28537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a563db2011-09-14 18:33:51538 ~vector()
539 {
540 __get_db()->__erase_c(this);
541 }
Howard Hinnantbc8d3f92010-05-11 19:42:16542#endif
543
544 vector(const vector& __x);
545 vector(const vector& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16547 vector& operator=(const vector& __x);
Howard Hinnant73d21a42010-09-04 23:28:19548#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40550 vector(vector&& __x)
Marshall Clow119ed472015-07-14 14:46:32551#if _LIBCPP_STD_VER > 14
552 _NOEXCEPT;
553#else
Howard Hinnantd1d27a42011-06-03 19:40:40554 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow119ed472015-07-14 14:46:32555#endif
Howard Hinnant2d72b1e2010-12-17 14:46:43556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16557 vector(vector&& __x, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40559 vector& operator=(vector&& __x)
Marshall Clowaf961ed2015-08-18 18:57:00560 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnant73d21a42010-09-04 23:28:19561#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02562#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16564 vector& operator=(initializer_list<value_type> __il)
565 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02566#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16567
568 template <class _InputIterator>
569 typename enable_if
570 <
571 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32572 !__is_forward_iterator<_InputIterator>::value &&
573 is_constructible<
574 value_type,
575 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16576 void
577 >::type
578 assign(_InputIterator __first, _InputIterator __last);
579 template <class _ForwardIterator>
580 typename enable_if
581 <
Howard Hinnant742fecb2013-03-28 17:44:32582 __is_forward_iterator<_ForwardIterator>::value &&
583 is_constructible<
584 value_type,
585 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16586 void
587 >::type
588 assign(_ForwardIterator __first, _ForwardIterator __last);
589
590 void assign(size_type __n, const_reference __u);
Howard Hinnante3e32912011-08-12 21:56:02591#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16593 void assign(initializer_list<value_type> __il)
594 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02595#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16596
Howard Hinnantd1d27a42011-06-03 19:40:40597 _LIBCPP_INLINE_VISIBILITY
598 allocator_type get_allocator() const _NOEXCEPT
599 {return this->__alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16600
Howard Hinnantd1d27a42011-06-03 19:40:40601 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
602 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
603 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
604 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16605
Howard Hinnantd1d27a42011-06-03 19:40:40606 _LIBCPP_INLINE_VISIBILITY
607 reverse_iterator rbegin() _NOEXCEPT
608 {return reverse_iterator(end());}
609 _LIBCPP_INLINE_VISIBILITY
610 const_reverse_iterator rbegin() const _NOEXCEPT
611 {return const_reverse_iterator(end());}
612 _LIBCPP_INLINE_VISIBILITY
613 reverse_iterator rend() _NOEXCEPT
614 {return reverse_iterator(begin());}
615 _LIBCPP_INLINE_VISIBILITY
616 const_reverse_iterator rend() const _NOEXCEPT
617 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16618
Howard Hinnantd1d27a42011-06-03 19:40:40619 _LIBCPP_INLINE_VISIBILITY
620 const_iterator cbegin() const _NOEXCEPT
621 {return begin();}
622 _LIBCPP_INLINE_VISIBILITY
623 const_iterator cend() const _NOEXCEPT
624 {return end();}
625 _LIBCPP_INLINE_VISIBILITY
626 const_reverse_iterator crbegin() const _NOEXCEPT
627 {return rbegin();}
628 _LIBCPP_INLINE_VISIBILITY
629 const_reverse_iterator crend() const _NOEXCEPT
630 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16631
Howard Hinnantd1d27a42011-06-03 19:40:40632 _LIBCPP_INLINE_VISIBILITY
633 size_type size() const _NOEXCEPT
634 {return static_cast<size_type>(this->__end_ - this->__begin_);}
635 _LIBCPP_INLINE_VISIBILITY
636 size_type capacity() const _NOEXCEPT
637 {return __base::capacity();}
638 _LIBCPP_INLINE_VISIBILITY
639 bool empty() const _NOEXCEPT
640 {return this->__begin_ == this->__end_;}
641 size_type max_size() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16642 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40643 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16644
645 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n);
646 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
647 reference at(size_type __n);
648 const_reference at(size_type __n) const;
649
Howard Hinnant7a563db2011-09-14 18:33:51650 _LIBCPP_INLINE_VISIBILITY reference front()
651 {
652 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
653 return *this->__begin_;
654 }
655 _LIBCPP_INLINE_VISIBILITY const_reference front() const
656 {
657 _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
658 return *this->__begin_;
659 }
660 _LIBCPP_INLINE_VISIBILITY reference back()
661 {
662 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
663 return *(this->__end_ - 1);
664 }
665 _LIBCPP_INLINE_VISIBILITY const_reference back() const
666 {
667 _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
668 return *(this->__end_ - 1);
669 }
Howard Hinnantbc8d3f92010-05-11 19:42:16670
Howard Hinnantd1d27a42011-06-03 19:40:40671 _LIBCPP_INLINE_VISIBILITY
672 value_type* data() _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19673 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantd1d27a42011-06-03 19:40:40674 _LIBCPP_INLINE_VISIBILITY
675 const value_type* data() const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19676 {return _VSTD::__to_raw_pointer(this->__begin_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16677
Howard Hinnant2d72b1e2010-12-17 14:46:43678 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19679#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb0bfd9b2012-02-15 00:41:34680 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19681#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16682 template <class... _Args>
Evgeniy Stepanova3b25f82015-11-07 01:22:13683 _LIBCPP_INLINE_VISIBILITY
Marshall Clow4e42dc92017-01-24 23:09:12684#if _LIBCPP_STD_VER > 14
Eric Fiselier3816ef92016-07-21 03:20:17685 reference emplace_back(_Args&&... __args);
Marshall Clow4e42dc92017-01-24 23:09:12686#else
687 void emplace_back(_Args&&... __args);
688#endif
Howard Hinnant73d21a42010-09-04 23:28:19689#endif // _LIBCPP_HAS_NO_VARIADICS
690#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanova3b25f82015-11-07 01:22:13691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16692 void pop_back();
693
694 iterator insert(const_iterator __position, const_reference __x);
Howard Hinnant73d21a42010-09-04 23:28:19695#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16696 iterator insert(const_iterator __position, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19697#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16698 template <class... _Args>
699 iterator emplace(const_iterator __position, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19700#endif // _LIBCPP_HAS_NO_VARIADICS
701#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16702 iterator insert(const_iterator __position, size_type __n, const_reference __x);
703 template <class _InputIterator>
704 typename enable_if
705 <
706 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:32707 !__is_forward_iterator<_InputIterator>::value &&
708 is_constructible<
709 value_type,
710 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16711 iterator
712 >::type
713 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
714 template <class _ForwardIterator>
715 typename enable_if
716 <
Howard Hinnant742fecb2013-03-28 17:44:32717 __is_forward_iterator<_ForwardIterator>::value &&
718 is_constructible<
719 value_type,
720 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16721 iterator
722 >::type
723 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02724#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16726 iterator insert(const_iterator __position, initializer_list<value_type> __il)
727 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02728#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16729
Howard Hinnant2d72b1e2010-12-17 14:46:43730 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:16731 iterator erase(const_iterator __first, const_iterator __last);
732
Howard Hinnantd1d27a42011-06-03 19:40:40733 _LIBCPP_INLINE_VISIBILITY
734 void clear() _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51735 {
Marshall Clow1f50f2d2014-05-08 14:14:06736 size_type __old_size = size();
Howard Hinnant7a563db2011-09-14 18:33:51737 __base::clear();
Marshall Clow1f50f2d2014-05-08 14:14:06738 __annotate_shrink(__old_size);
Howard Hinnant7a563db2011-09-14 18:33:51739 __invalidate_all_iterators();
740 }
Howard Hinnantbc8d3f92010-05-11 19:42:16741
742 void resize(size_type __sz);
743 void resize(size_type __sz, const_reference __x);
744
Howard Hinnantd1d27a42011-06-03 19:40:40745 void swap(vector&)
Marshall Clow7d914d12015-07-13 20:04:56746#if _LIBCPP_STD_VER >= 14
Eric Fiselierfb342382016-12-28 06:06:09747 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56748#else
Eric Fiselierfb342382016-12-28 06:06:09749 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56750 __is_nothrow_swappable<allocator_type>::value);
751#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16752
753 bool __invariants() const;
754
Howard Hinnantabe26282011-09-16 17:29:17755#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51756
757 bool __dereferenceable(const const_iterator* __i) const;
758 bool __decrementable(const const_iterator* __i) const;
759 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
760 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
761
Howard Hinnantabe26282011-09-16 17:29:17762#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:51763
Howard Hinnantbc8d3f92010-05-11 19:42:16764private:
Howard Hinnant2d72b1e2010-12-17 14:46:43765 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Eric Fiselierfb342382016-12-28 06:06:09766 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
Howard Hinnantbc8d3f92010-05-11 19:42:16767 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:40768 void deallocate() _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43769 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
Howard Hinnant04240d92011-01-04 19:53:31770 void __construct_at_end(size_type __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16772 void __construct_at_end(size_type __n, const_reference __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16773 template <class _ForwardIterator>
774 typename enable_if
775 <
776 __is_forward_iterator<_ForwardIterator>::value,
777 void
778 >::type
Eric Fiselier088ed9f2015-03-31 16:54:19779 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16780 void __append(size_type __n);
781 void __append(size_type __n, const_reference __x);
Howard Hinnant2d72b1e2010-12-17 14:46:43782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40783 iterator __make_iter(pointer __p) _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:40785 const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16786 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
787 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
788 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
Howard Hinnantd1d27a42011-06-03 19:40:40789 void __move_assign(vector& __c, true_type)
790 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Marshall Clowaf961ed2015-08-18 18:57:00791 void __move_assign(vector& __c, false_type)
792 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant7a563db2011-09-14 18:33:51793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant2c39cbe2013-06-27 19:35:32794 void __destruct_at_end(pointer __new_last) _NOEXCEPT
Howard Hinnant7a563db2011-09-14 18:33:51795 {
Eric Fiselierfb342382016-12-28 06:06:09796 __invalidate_iterators_past(__new_last);
Marshall Clow1f50f2d2014-05-08 14:14:06797 size_type __old_size = size();
Howard Hinnant7a563db2011-09-14 18:33:51798 __base::__destruct_at_end(__new_last);
Marshall Clow1f50f2d2014-05-08 14:14:06799 __annotate_shrink(__old_size);
Howard Hinnant7a563db2011-09-14 18:33:51800 }
Howard Hinnantb0bfd9b2012-02-15 00:41:34801 template <class _Up>
802 void
803#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
804 __push_back_slow_path(_Up&& __x);
805#else
806 __push_back_slow_path(_Up& __x);
807#endif
Howard Hinnant0438ea22012-02-26 15:30:12808#if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
809 template <class... _Args>
810 void
811 __emplace_back_slow_path(_Args&&... __args);
812#endif
Marshall Clow1f50f2d2014-05-08 14:14:06813 // The following functions are no-ops outside of AddressSanitizer mode.
814 // We call annotatations only for the default Allocator because other allocators
815 // may not meet the AddressSanitizer alignment constraints.
816 // See the documentation for __sanitizer_annotate_contiguous_container for more details.
Marshall Clow1f50f2d2014-05-08 14:14:06817#ifndef _LIBCPP_HAS_NO_ASAN
Eric Fiselier0e5ebbc2016-12-23 23:37:52818 void __annotate_contiguous_container(const void *__beg, const void *__end,
819 const void *__old_mid,
820 const void *__new_mid) const
821 {
822
Marshall Clow1f50f2d2014-05-08 14:14:06823 if (__beg && is_same<allocator_type, __default_allocator_type>::value)
824 __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
Marshall Clow1f50f2d2014-05-08 14:14:06825 }
Eric Fiselier0e5ebbc2016-12-23 23:37:52826#else
827 _LIBCPP_INLINE_VISIBILITY
828 void __annotate_contiguous_container(const void*, const void*, const void*,
829 const void*) const {}
830#endif
831 _LIBCPP_INLINE_VISIBILITY
832 void __annotate_new(size_type __current_size) const {
Marshall Clow1f50f2d2014-05-08 14:14:06833 __annotate_contiguous_container(data(), data() + capacity(),
834 data() + capacity(), data() + __current_size);
835 }
Eric Fiselier0e5ebbc2016-12-23 23:37:52836
837 _LIBCPP_INLINE_VISIBILITY
838 void __annotate_delete() const {
Marshall Clow1f50f2d2014-05-08 14:14:06839 __annotate_contiguous_container(data(), data() + capacity(),
840 data() + size(), data() + capacity());
841 }
Eric Fiselier0e5ebbc2016-12-23 23:37:52842
843 _LIBCPP_INLINE_VISIBILITY
Kostya Serebryany497f9122014-09-02 23:43:38844 void __annotate_increase(size_type __n) const
Marshall Clow1f50f2d2014-05-08 14:14:06845 {
846 __annotate_contiguous_container(data(), data() + capacity(),
847 data() + size(), data() + size() + __n);
848 }
Eric Fiselier0e5ebbc2016-12-23 23:37:52849
850 _LIBCPP_INLINE_VISIBILITY
Kostya Serebryany497f9122014-09-02 23:43:38851 void __annotate_shrink(size_type __old_size) const
Marshall Clow1f50f2d2014-05-08 14:14:06852 {
853 __annotate_contiguous_container(data(), data() + capacity(),
854 data() + __old_size, data() + size());
855 }
Marshall Clow26f472d2014-09-03 21:37:43856#ifndef _LIBCPP_HAS_NO_ASAN
Kostya Serebryany497f9122014-09-02 23:43:38857 // The annotation for size increase should happen before the actual increase,
858 // but if an exception is thrown after that the annotation has to be undone.
859 struct __RAII_IncreaseAnnotator {
860 __RAII_IncreaseAnnotator(const vector &__v, size_type __n = 1)
Eric Fiselier9f4f2212015-03-10 00:25:20861 : __commit(false), __v(__v), __old_size(__v.size() + __n) {
Kostya Serebryany497f9122014-09-02 23:43:38862 __v.__annotate_increase(__n);
863 }
864 void __done() { __commit = true; }
865 ~__RAII_IncreaseAnnotator() {
866 if (__commit) return;
Eric Fiselier9f4f2212015-03-10 00:25:20867 __v.__annotate_shrink(__old_size);
Kostya Serebryany497f9122014-09-02 23:43:38868 }
869 bool __commit;
Kostya Serebryany497f9122014-09-02 23:43:38870 const vector &__v;
Eric Fiselier9f4f2212015-03-10 00:25:20871 size_type __old_size;
Kostya Serebryany497f9122014-09-02 23:43:38872 };
Marshall Clow26f472d2014-09-03 21:37:43873#else
874 struct __RAII_IncreaseAnnotator {
Eric Fiselier0e5ebbc2016-12-23 23:37:52875 _LIBCPP_INLINE_VISIBILITY
876 __RAII_IncreaseAnnotator(const vector &, size_type = 1) {}
877 _LIBCPP_INLINE_VISIBILITY void __done() {}
Marshall Clow26f472d2014-09-03 21:37:43878 };
879#endif
880
Howard Hinnantbc8d3f92010-05-11 19:42:16881};
882
883template <class _Tp, class _Allocator>
884void
885vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
886{
Marshall Clow1f50f2d2014-05-08 14:14:06887 __annotate_delete();
Howard Hinnantb0bfd9b2012-02-15 00:41:34888 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
Howard Hinnant0949eed2011-06-30 21:18:19889 _VSTD::swap(this->__begin_, __v.__begin_);
890 _VSTD::swap(this->__end_, __v.__end_);
891 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16892 __v.__first_ = __v.__begin_;
Marshall Clow1f50f2d2014-05-08 14:14:06893 __annotate_new(size());
Howard Hinnantbc8d3f92010-05-11 19:42:16894 __invalidate_all_iterators();
895}
896
897template <class _Tp, class _Allocator>
898typename vector<_Tp, _Allocator>::pointer
899vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
900{
Marshall Clow1f50f2d2014-05-08 14:14:06901 __annotate_delete();
Howard Hinnantbc8d3f92010-05-11 19:42:16902 pointer __r = __v.__begin_;
Howard Hinnantb0bfd9b2012-02-15 00:41:34903 __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_);
904 __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_);
Howard Hinnant0949eed2011-06-30 21:18:19905 _VSTD::swap(this->__begin_, __v.__begin_);
906 _VSTD::swap(this->__end_, __v.__end_);
907 _VSTD::swap(this->__end_cap(), __v.__end_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16908 __v.__first_ = __v.__begin_;
Marshall Clow1f50f2d2014-05-08 14:14:06909 __annotate_new(size());
Howard Hinnantbc8d3f92010-05-11 19:42:16910 __invalidate_all_iterators();
911 return __r;
912}
913
914// Allocate space for __n objects
915// throws length_error if __n > max_size()
916// throws (probably bad_alloc) if memory run out
917// Precondition: __begin_ == __end_ == __end_cap() == 0
918// Precondition: __n > 0
919// Postcondition: capacity() == __n
920// Postcondition: size() == 0
921template <class _Tp, class _Allocator>
922void
923vector<_Tp, _Allocator>::allocate(size_type __n)
924{
925 if (__n > max_size())
926 this->__throw_length_error();
927 this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
928 this->__end_cap() = this->__begin_ + __n;
Marshall Clow1f50f2d2014-05-08 14:14:06929 __annotate_new(0);
Howard Hinnantbc8d3f92010-05-11 19:42:16930}
931
932template <class _Tp, class _Allocator>
933void
Howard Hinnantd1d27a42011-06-03 19:40:40934vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16935{
Howard Hinnant2c39cbe2013-06-27 19:35:32936 if (this->__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16937 {
938 clear();
939 __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
Howard Hinnant2c39cbe2013-06-27 19:35:32940 this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16941 }
942}
943
944template <class _Tp, class _Allocator>
945typename vector<_Tp, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:40946vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16947{
Eric Fiselieref3060e2016-11-23 01:18:56948 return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()),
949 numeric_limits<difference_type>::max());
Howard Hinnantbc8d3f92010-05-11 19:42:16950}
951
952// Precondition: __new_size > capacity()
953template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00954inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16955typename vector<_Tp, _Allocator>::size_type
956vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
957{
958 const size_type __ms = max_size();
959 if (__new_size > __ms)
960 this->__throw_length_error();
961 const size_type __cap = capacity();
962 if (__cap >= __ms / 2)
963 return __ms;
Sean Hunt110b8bf2011-07-29 23:31:58964 return _VSTD::max<size_type>(2*__cap, __new_size);
Howard Hinnantbc8d3f92010-05-11 19:42:16965}
966
967// Default constructs __n objects starting at __end_
968// throws if construction throws
969// Precondition: __n > 0
970// Precondition: size() + __n <= capacity()
971// Postcondition: size() == size() + __n
972template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16973void
974vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
975{
Howard Hinnantbc8d3f92010-05-11 19:42:16976 allocator_type& __a = this->__alloc();
977 do
978 {
Kostya Serebryany497f9122014-09-02 23:43:38979 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnant0949eed2011-06-30 21:18:19980 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
Howard Hinnantbc8d3f92010-05-11 19:42:16981 ++this->__end_;
982 --__n;
Kostya Serebryany497f9122014-09-02 23:43:38983 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:16984 } while (__n > 0);
985}
986
Howard Hinnantbc8d3f92010-05-11 19:42:16987// Copy constructs __n objects starting at __end_ from __x
988// throws if construction throws
989// Precondition: __n > 0
990// Precondition: size() + __n <= capacity()
991// Postcondition: size() == old size() + __n
992// Postcondition: [i] == __x for all i in [size() - __n, __n)
993template <class _Tp, class _Allocator>
Evgeniy Stepanova3b25f82015-11-07 01:22:13994inline
Howard Hinnantbc8d3f92010-05-11 19:42:16995void
996vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
997{
Howard Hinnantbc8d3f92010-05-11 19:42:16998 allocator_type& __a = this->__alloc();
999 do
1000 {
Kostya Serebryany497f9122014-09-02 23:43:381001 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnant0949eed2011-06-30 21:18:191002 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161003 ++this->__end_;
1004 --__n;
Kostya Serebryany497f9122014-09-02 23:43:381005 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:161006 } while (__n > 0);
1007}
1008
1009template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161010template <class _ForwardIterator>
1011typename enable_if
1012<
1013 __is_forward_iterator<_ForwardIterator>::value,
1014 void
1015>::type
Eric Fiselier088ed9f2015-03-31 16:54:191016vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:161017{
1018 allocator_type& __a = this->__alloc();
Eric Fiselier088ed9f2015-03-31 16:54:191019 __RAII_IncreaseAnnotator __annotator(*this, __n);
1020 __alloc_traits::__construct_range_forward(__a, __first, __last, this->__end_);
1021 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:161022}
1023
1024// Default constructs __n objects starting at __end_
1025// throws if construction throws
1026// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:401027// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:161028template <class _Tp, class _Allocator>
1029void
1030vector<_Tp, _Allocator>::__append(size_type __n)
1031{
1032 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1033 this->__construct_at_end(__n);
1034 else
1035 {
1036 allocator_type& __a = this->__alloc();
1037 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1038 __v.__construct_at_end(__n);
1039 __swap_out_circular_buffer(__v);
1040 }
1041}
1042
1043// Default constructs __n objects starting at __end_
1044// throws if construction throws
1045// Postcondition: size() == size() + __n
Howard Hinnantd1d27a42011-06-03 19:40:401046// Exception safety: strong.
Howard Hinnantbc8d3f92010-05-11 19:42:161047template <class _Tp, class _Allocator>
1048void
1049vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
1050{
1051 if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
1052 this->__construct_at_end(__n, __x);
1053 else
1054 {
1055 allocator_type& __a = this->__alloc();
1056 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
1057 __v.__construct_at_end(__n, __x);
1058 __swap_out_circular_buffer(__v);
1059 }
1060}
1061
1062template <class _Tp, class _Allocator>
1063vector<_Tp, _Allocator>::vector(size_type __n)
1064{
Howard Hinnant0442b122011-09-16 18:41:291065#if _LIBCPP_DEBUG_LEVEL >= 2
1066 __get_db()->__insert_c(this);
1067#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161068 if (__n > 0)
1069 {
1070 allocate(__n);
1071 __construct_at_end(__n);
1072 }
1073}
1074
Marshall Clowa49a2c92013-09-14 00:47:591075#if _LIBCPP_STD_VER > 11
1076template <class _Tp, class _Allocator>
1077vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1078 : __base(__a)
1079{
1080#if _LIBCPP_DEBUG_LEVEL >= 2
1081 __get_db()->__insert_c(this);
1082#endif
1083 if (__n > 0)
1084 {
1085 allocate(__n);
1086 __construct_at_end(__n);
1087 }
1088}
1089#endif
1090
Howard Hinnantbc8d3f92010-05-11 19:42:161091template <class _Tp, class _Allocator>
1092vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
1093{
Howard Hinnant0442b122011-09-16 18:41:291094#if _LIBCPP_DEBUG_LEVEL >= 2
1095 __get_db()->__insert_c(this);
1096#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161097 if (__n > 0)
1098 {
1099 allocate(__n);
1100 __construct_at_end(__n, __x);
1101 }
1102}
1103
1104template <class _Tp, class _Allocator>
1105vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1106 : __base(__a)
1107{
Howard Hinnant0442b122011-09-16 18:41:291108#if _LIBCPP_DEBUG_LEVEL >= 2
1109 __get_db()->__insert_c(this);
1110#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161111 if (__n > 0)
1112 {
1113 allocate(__n);
1114 __construct_at_end(__n, __x);
1115 }
1116}
1117
1118template <class _Tp, class _Allocator>
1119template <class _InputIterator>
Howard Hinnantde589f22013-09-21 21:13:541120vector<_Tp, _Allocator>::vector(_InputIterator __first,
Howard Hinnantbc8d3f92010-05-11 19:42:161121 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:321122 !__is_forward_iterator<_InputIterator>::value &&
1123 is_constructible<
1124 value_type,
Howard Hinnantde589f22013-09-21 21:13:541125 typename iterator_traits<_InputIterator>::reference>::value,
1126 _InputIterator>::type __last)
Howard Hinnantbc8d3f92010-05-11 19:42:161127{
Howard Hinnantabe26282011-09-16 17:29:171128#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511129 __get_db()->__insert_c(this);
1130#endif
Howard Hinnant0442b122011-09-16 18:41:291131 for (; __first != __last; ++__first)
1132 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:161133}
1134
1135template <class _Tp, class _Allocator>
1136template <class _InputIterator>
1137vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1138 typename enable_if<__is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:321139 !__is_forward_iterator<_InputIterator>::value &&
1140 is_constructible<
1141 value_type,
1142 typename iterator_traits<_InputIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:161143 : __base(__a)
1144{
Howard Hinnantabe26282011-09-16 17:29:171145#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511146 __get_db()->__insert_c(this);
1147#endif
Howard Hinnant0442b122011-09-16 18:41:291148 for (; __first != __last; ++__first)
1149 push_back(*__first);
Howard Hinnantbc8d3f92010-05-11 19:42:161150}
1151
1152template <class _Tp, class _Allocator>
1153template <class _ForwardIterator>
Howard Hinnantde589f22013-09-21 21:13:541154vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
Howard Hinnant742fecb2013-03-28 17:44:321155 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1156 is_constructible<
1157 value_type,
Howard Hinnantde589f22013-09-21 21:13:541158 typename iterator_traits<_ForwardIterator>::reference>::value,
1159 _ForwardIterator>::type __last)
Howard Hinnantbc8d3f92010-05-11 19:42:161160{
Howard Hinnant0442b122011-09-16 18:41:291161#if _LIBCPP_DEBUG_LEVEL >= 2
1162 __get_db()->__insert_c(this);
1163#endif
Howard Hinnant0949eed2011-06-30 21:18:191164 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:161165 if (__n > 0)
1166 {
1167 allocate(__n);
Eric Fiselier088ed9f2015-03-31 16:54:191168 __construct_at_end(__first, __last, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161169 }
1170}
1171
1172template <class _Tp, class _Allocator>
1173template <class _ForwardIterator>
1174vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
Howard Hinnant742fecb2013-03-28 17:44:321175 typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
1176 is_constructible<
1177 value_type,
1178 typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:161179 : __base(__a)
1180{
Howard Hinnant0442b122011-09-16 18:41:291181#if _LIBCPP_DEBUG_LEVEL >= 2
1182 __get_db()->__insert_c(this);
1183#endif
Howard Hinnant0949eed2011-06-30 21:18:191184 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:161185 if (__n > 0)
1186 {
1187 allocate(__n);
Eric Fiselier088ed9f2015-03-31 16:54:191188 __construct_at_end(__first, __last, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161189 }
1190}
1191
1192template <class _Tp, class _Allocator>
1193vector<_Tp, _Allocator>::vector(const vector& __x)
1194 : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1195{
Howard Hinnant0442b122011-09-16 18:41:291196#if _LIBCPP_DEBUG_LEVEL >= 2
1197 __get_db()->__insert_c(this);
1198#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161199 size_type __n = __x.size();
1200 if (__n > 0)
1201 {
1202 allocate(__n);
Eric Fiselier088ed9f2015-03-31 16:54:191203 __construct_at_end(__x.__begin_, __x.__end_, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161204 }
1205}
1206
1207template <class _Tp, class _Allocator>
1208vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1209 : __base(__a)
1210{
Howard Hinnant0442b122011-09-16 18:41:291211#if _LIBCPP_DEBUG_LEVEL >= 2
1212 __get_db()->__insert_c(this);
1213#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161214 size_type __n = __x.size();
1215 if (__n > 0)
1216 {
1217 allocate(__n);
Eric Fiselier088ed9f2015-03-31 16:54:191218 __construct_at_end(__x.__begin_, __x.__end_, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161219 }
1220}
1221
Howard Hinnant73d21a42010-09-04 23:28:191222#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161223
1224template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001225inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161226vector<_Tp, _Allocator>::vector(vector&& __x)
Marshall Clow119ed472015-07-14 14:46:321227#if _LIBCPP_STD_VER > 14
1228 _NOEXCEPT
1229#else
Howard Hinnantd1d27a42011-06-03 19:40:401230 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow119ed472015-07-14 14:46:321231#endif
Howard Hinnant0949eed2011-06-30 21:18:191232 : __base(_VSTD::move(__x.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:161233{
Howard Hinnantabe26282011-09-16 17:29:171234#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511235 __get_db()->__insert_c(this);
Howard Hinnante6125bd2011-09-19 16:34:291236 __get_db()->swap(this, &__x);
Howard Hinnant7a563db2011-09-14 18:33:511237#endif
Howard Hinnant0442b122011-09-16 18:41:291238 this->__begin_ = __x.__begin_;
1239 this->__end_ = __x.__end_;
1240 this->__end_cap() = __x.__end_cap();
Howard Hinnant2c39cbe2013-06-27 19:35:321241 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:161242}
1243
1244template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001245inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161246vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1247 : __base(__a)
1248{
Howard Hinnant0442b122011-09-16 18:41:291249#if _LIBCPP_DEBUG_LEVEL >= 2
1250 __get_db()->__insert_c(this);
1251#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161252 if (__a == __x.__alloc())
1253 {
1254 this->__begin_ = __x.__begin_;
1255 this->__end_ = __x.__end_;
1256 this->__end_cap() = __x.__end_cap();
1257 __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:291258#if _LIBCPP_DEBUG_LEVEL >= 2
1259 __get_db()->swap(this, &__x);
1260#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161261 }
1262 else
1263 {
Howard Hinnant99968442011-11-29 18:15:501264 typedef move_iterator<iterator> _Ip;
1265 assign(_Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161266 }
1267}
1268
Howard Hinnante3e32912011-08-12 21:56:021269#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1270
Howard Hinnantbc8d3f92010-05-11 19:42:161271template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001272inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161273vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1274{
Howard Hinnant0442b122011-09-16 18:41:291275#if _LIBCPP_DEBUG_LEVEL >= 2
1276 __get_db()->__insert_c(this);
1277#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161278 if (__il.size() > 0)
1279 {
1280 allocate(__il.size());
Eric Fiselier088ed9f2015-03-31 16:54:191281 __construct_at_end(__il.begin(), __il.end(), __il.size());
Howard Hinnantbc8d3f92010-05-11 19:42:161282 }
1283}
1284
1285template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001286inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161287vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1288 : __base(__a)
1289{
Howard Hinnant0442b122011-09-16 18:41:291290#if _LIBCPP_DEBUG_LEVEL >= 2
1291 __get_db()->__insert_c(this);
1292#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161293 if (__il.size() > 0)
1294 {
1295 allocate(__il.size());
Eric Fiselier088ed9f2015-03-31 16:54:191296 __construct_at_end(__il.begin(), __il.end(), __il.size());
Howard Hinnantbc8d3f92010-05-11 19:42:161297 }
1298}
1299
Howard Hinnante3e32912011-08-12 21:56:021300#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1301
Howard Hinnantbc8d3f92010-05-11 19:42:161302template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001303inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161304vector<_Tp, _Allocator>&
1305vector<_Tp, _Allocator>::operator=(vector&& __x)
Marshall Clowaf961ed2015-08-18 18:57:001306 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:161307{
1308 __move_assign(__x, integral_constant<bool,
1309 __alloc_traits::propagate_on_container_move_assignment::value>());
1310 return *this;
1311}
1312
1313template <class _Tp, class _Allocator>
1314void
1315vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
Marshall Clowaf961ed2015-08-18 18:57:001316 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161317{
1318 if (__base::__alloc() != __c.__alloc())
1319 {
Howard Hinnant99968442011-11-29 18:15:501320 typedef move_iterator<iterator> _Ip;
1321 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161322 }
1323 else
1324 __move_assign(__c, true_type());
1325}
1326
1327template <class _Tp, class _Allocator>
1328void
1329vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:401330 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161331{
1332 deallocate();
Marshall Clow3c2eac62014-07-21 15:11:131333 __base::__move_assign_alloc(__c); // this can throw
Howard Hinnantbc8d3f92010-05-11 19:42:161334 this->__begin_ = __c.__begin_;
1335 this->__end_ = __c.__end_;
1336 this->__end_cap() = __c.__end_cap();
Howard Hinnantbc8d3f92010-05-11 19:42:161337 __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
Howard Hinnante6125bd2011-09-19 16:34:291338#if _LIBCPP_DEBUG_LEVEL >= 2
1339 __get_db()->swap(this, &__c);
1340#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161341}
1342
Howard Hinnant73d21a42010-09-04 23:28:191343#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161344
1345template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001346inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161347vector<_Tp, _Allocator>&
1348vector<_Tp, _Allocator>::operator=(const vector& __x)
1349{
1350 if (this != &__x)
1351 {
1352 __base::__copy_assign_alloc(__x);
1353 assign(__x.__begin_, __x.__end_);
1354 }
1355 return *this;
1356}
1357
1358template <class _Tp, class _Allocator>
1359template <class _InputIterator>
1360typename enable_if
1361<
1362 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:321363 !__is_forward_iterator<_InputIterator>::value &&
1364 is_constructible<
1365 _Tp,
1366 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161367 void
1368>::type
1369vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1370{
1371 clear();
1372 for (; __first != __last; ++__first)
1373 push_back(*__first);
1374}
1375
1376template <class _Tp, class _Allocator>
1377template <class _ForwardIterator>
1378typename enable_if
1379<
Howard Hinnant742fecb2013-03-28 17:44:321380 __is_forward_iterator<_ForwardIterator>::value &&
1381 is_constructible<
1382 _Tp,
1383 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161384 void
1385>::type
1386vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1387{
Eric Fiselier088ed9f2015-03-31 16:54:191388 size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
1389 if (__new_size <= capacity())
Howard Hinnantbc8d3f92010-05-11 19:42:161390 {
1391 _ForwardIterator __mid = __last;
1392 bool __growing = false;
Eric Fiselier088ed9f2015-03-31 16:54:191393 if (__new_size > size())
Howard Hinnantbc8d3f92010-05-11 19:42:161394 {
1395 __growing = true;
1396 __mid = __first;
Howard Hinnant0949eed2011-06-30 21:18:191397 _VSTD::advance(__mid, size());
Howard Hinnantbc8d3f92010-05-11 19:42:161398 }
Howard Hinnant0949eed2011-06-30 21:18:191399 pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:161400 if (__growing)
Eric Fiselier088ed9f2015-03-31 16:54:191401 __construct_at_end(__mid, __last, __new_size - size());
Howard Hinnantbc8d3f92010-05-11 19:42:161402 else
1403 this->__destruct_at_end(__m);
1404 }
1405 else
1406 {
1407 deallocate();
Eric Fiselier088ed9f2015-03-31 16:54:191408 allocate(__recommend(__new_size));
1409 __construct_at_end(__first, __last, __new_size);
Howard Hinnantbc8d3f92010-05-11 19:42:161410 }
Eric Fiselierfb342382016-12-28 06:06:091411 __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:161412}
1413
1414template <class _Tp, class _Allocator>
1415void
1416vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1417{
1418 if (__n <= capacity())
1419 {
1420 size_type __s = size();
Howard Hinnant0949eed2011-06-30 21:18:191421 _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
Howard Hinnantbc8d3f92010-05-11 19:42:161422 if (__n > __s)
1423 __construct_at_end(__n - __s, __u);
1424 else
Howard Hinnantadff4892010-05-24 17:49:411425 this->__destruct_at_end(this->__begin_ + __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161426 }
1427 else
1428 {
1429 deallocate();
1430 allocate(__recommend(static_cast<size_type>(__n)));
1431 __construct_at_end(__n, __u);
1432 }
Eric Fiselierfb342382016-12-28 06:06:091433 __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:161434}
1435
Howard Hinnant324bb032010-08-22 00:02:431436template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001437inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161438typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:401439vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161440{
Howard Hinnantabe26282011-09-16 17:29:171441#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:161442 return iterator(this, __p);
1443#else
1444 return iterator(__p);
1445#endif
1446}
1447
Howard Hinnant324bb032010-08-22 00:02:431448template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001449inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161450typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:401451vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161452{
Howard Hinnantabe26282011-09-16 17:29:171453#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:161454 return const_iterator(this, __p);
1455#else
1456 return const_iterator(__p);
1457#endif
1458}
1459
Howard Hinnant324bb032010-08-22 00:02:431460template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001461inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161462typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:401463vector<_Tp, _Allocator>::begin() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161464{
1465 return __make_iter(this->__begin_);
1466}
1467
Howard Hinnant324bb032010-08-22 00:02:431468template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001469inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161470typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:401471vector<_Tp, _Allocator>::begin() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161472{
1473 return __make_iter(this->__begin_);
1474}
1475
Howard Hinnant324bb032010-08-22 00:02:431476template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001477inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161478typename vector<_Tp, _Allocator>::iterator
Howard Hinnantd1d27a42011-06-03 19:40:401479vector<_Tp, _Allocator>::end() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161480{
1481 return __make_iter(this->__end_);
1482}
1483
Howard Hinnant324bb032010-08-22 00:02:431484template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001485inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161486typename vector<_Tp, _Allocator>::const_iterator
Howard Hinnantd1d27a42011-06-03 19:40:401487vector<_Tp, _Allocator>::end() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161488{
1489 return __make_iter(this->__end_);
1490}
1491
Howard Hinnant324bb032010-08-22 00:02:431492template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001493inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161494typename vector<_Tp, _Allocator>::reference
1495vector<_Tp, _Allocator>::operator[](size_type __n)
1496{
Howard Hinnant7a563db2011-09-14 18:33:511497 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:161498 return this->__begin_[__n];
1499}
1500
Howard Hinnant324bb032010-08-22 00:02:431501template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001502inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161503typename vector<_Tp, _Allocator>::const_reference
1504vector<_Tp, _Allocator>::operator[](size_type __n) const
1505{
Howard Hinnant7a563db2011-09-14 18:33:511506 _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:161507 return this->__begin_[__n];
1508}
1509
Howard Hinnant324bb032010-08-22 00:02:431510template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161511typename vector<_Tp, _Allocator>::reference
1512vector<_Tp, _Allocator>::at(size_type __n)
1513{
1514 if (__n >= size())
1515 this->__throw_out_of_range();
1516 return this->__begin_[__n];
1517}
1518
Howard Hinnant324bb032010-08-22 00:02:431519template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:161520typename vector<_Tp, _Allocator>::const_reference
1521vector<_Tp, _Allocator>::at(size_type __n) const
1522{
1523 if (__n >= size())
1524 this->__throw_out_of_range();
1525 return this->__begin_[__n];
1526}
1527
1528template <class _Tp, class _Allocator>
1529void
1530vector<_Tp, _Allocator>::reserve(size_type __n)
1531{
1532 if (__n > capacity())
1533 {
1534 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:401535 __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:161536 __swap_out_circular_buffer(__v);
1537 }
1538}
1539
1540template <class _Tp, class _Allocator>
1541void
Howard Hinnantd1d27a42011-06-03 19:40:401542vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161543{
1544 if (capacity() > size())
1545 {
1546#ifndef _LIBCPP_NO_EXCEPTIONS
1547 try
1548 {
Howard Hinnant324bb032010-08-22 00:02:431549#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161550 allocator_type& __a = this->__alloc();
Howard Hinnantd1d27a42011-06-03 19:40:401551 __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
Howard Hinnantbc8d3f92010-05-11 19:42:161552 __swap_out_circular_buffer(__v);
1553#ifndef _LIBCPP_NO_EXCEPTIONS
1554 }
1555 catch (...)
1556 {
1557 }
Howard Hinnant324bb032010-08-22 00:02:431558#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161559 }
1560}
1561
1562template <class _Tp, class _Allocator>
Howard Hinnantb0bfd9b2012-02-15 00:41:341563template <class _Up>
1564void
1565#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1566vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
1567#else
1568vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
1569#endif
1570{
1571 allocator_type& __a = this->__alloc();
1572 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1573 // __v.push_back(_VSTD::forward<_Up>(__x));
Howard Hinnantf619e232013-01-11 20:36:591574 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
1575 __v.__end_++;
Howard Hinnantb0bfd9b2012-02-15 00:41:341576 __swap_out_circular_buffer(__v);
1577}
1578
1579template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001580inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161581void
1582vector<_Tp, _Allocator>::push_back(const_reference __x)
1583{
Howard Hinnantb0bfd9b2012-02-15 00:41:341584 if (this->__end_ != this->__end_cap())
Howard Hinnantbc8d3f92010-05-11 19:42:161585 {
Kostya Serebryany497f9122014-09-02 23:43:381586 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:161587 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191588 _VSTD::__to_raw_pointer(this->__end_), __x);
Kostya Serebryany497f9122014-09-02 23:43:381589 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:161590 ++this->__end_;
1591 }
1592 else
Howard Hinnantb0bfd9b2012-02-15 00:41:341593 __push_back_slow_path(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:161594}
1595
Howard Hinnant73d21a42010-09-04 23:28:191596#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161597
1598template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001599inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161600void
1601vector<_Tp, _Allocator>::push_back(value_type&& __x)
1602{
1603 if (this->__end_ < this->__end_cap())
1604 {
Kostya Serebryany497f9122014-09-02 23:43:381605 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:161606 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191607 _VSTD::__to_raw_pointer(this->__end_),
1608 _VSTD::move(__x));
Kostya Serebryany497f9122014-09-02 23:43:381609 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:161610 ++this->__end_;
1611 }
1612 else
Howard Hinnantb0bfd9b2012-02-15 00:41:341613 __push_back_slow_path(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:161614}
1615
Howard Hinnant73d21a42010-09-04 23:28:191616#ifndef _LIBCPP_HAS_NO_VARIADICS
1617
Howard Hinnantbc8d3f92010-05-11 19:42:161618template <class _Tp, class _Allocator>
1619template <class... _Args>
1620void
Howard Hinnant0438ea22012-02-26 15:30:121621vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
1622{
1623 allocator_type& __a = this->__alloc();
1624 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1625// __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantf619e232013-01-11 20:36:591626 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
1627 __v.__end_++;
Howard Hinnant0438ea22012-02-26 15:30:121628 __swap_out_circular_buffer(__v);
1629}
1630
1631template <class _Tp, class _Allocator>
1632template <class... _Args>
Evgeniy Stepanova3b25f82015-11-07 01:22:131633inline
Marshall Clow4e42dc92017-01-24 23:09:121634#if _LIBCPP_STD_VER > 14
Eric Fiselier3816ef92016-07-21 03:20:171635typename vector<_Tp, _Allocator>::reference
Marshall Clow4e42dc92017-01-24 23:09:121636#else
1637void
1638#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161639vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1640{
1641 if (this->__end_ < this->__end_cap())
1642 {
Kostya Serebryany497f9122014-09-02 23:43:381643 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:161644 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191645 _VSTD::__to_raw_pointer(this->__end_),
1646 _VSTD::forward<_Args>(__args)...);
Kostya Serebryany497f9122014-09-02 23:43:381647 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:161648 ++this->__end_;
1649 }
1650 else
Howard Hinnant0438ea22012-02-26 15:30:121651 __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
Marshall Clow4e42dc92017-01-24 23:09:121652#if _LIBCPP_STD_VER > 14
Eric Fiselier3816ef92016-07-21 03:20:171653 return this->back();
Marshall Clow4e42dc92017-01-24 23:09:121654#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161655}
1656
Howard Hinnant73d21a42010-09-04 23:28:191657#endif // _LIBCPP_HAS_NO_VARIADICS
1658#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161659
1660template <class _Tp, class _Allocator>
Evgeniy Stepanova3b25f82015-11-07 01:22:131661inline
Howard Hinnantbc8d3f92010-05-11 19:42:161662void
1663vector<_Tp, _Allocator>::pop_back()
1664{
Howard Hinnant7a563db2011-09-14 18:33:511665 _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
Howard Hinnantbc8d3f92010-05-11 19:42:161666 this->__destruct_at_end(this->__end_ - 1);
1667}
1668
1669template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:001670inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161671typename vector<_Tp, _Allocator>::iterator
1672vector<_Tp, _Allocator>::erase(const_iterator __position)
1673{
Howard Hinnantabe26282011-09-16 17:29:171674#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511675 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1676 "vector::erase(iterator) called with an iterator not"
1677 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171678#endif
Howard Hinnant782da332013-03-25 22:12:261679 _LIBCPP_ASSERT(__position != end(),
1680 "vector::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnant2c39cbe2013-06-27 19:35:321681 difference_type __ps = __position - cbegin();
1682 pointer __p = this->__begin_ + __ps;
Howard Hinnant0949eed2011-06-30 21:18:191683 this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
Eric Fiselierfb342382016-12-28 06:06:091684 this->__invalidate_iterators_past(__p-1);
1685 iterator __r = __make_iter(__p);
Howard Hinnantbc8d3f92010-05-11 19:42:161686 return __r;
1687}
1688
1689template <class _Tp, class _Allocator>
1690typename vector<_Tp, _Allocator>::iterator
1691vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1692{
Howard Hinnantabe26282011-09-16 17:29:171693#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511694 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1695 "vector::erase(iterator, iterator) called with an iterator not"
1696 " referring to this vector");
Eric Fiselierfb342382016-12-28 06:06:091697 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
1698 "vector::erase(iterator, iterator) called with an iterator not"
1699 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171700#endif
Howard Hinnant7a563db2011-09-14 18:33:511701 _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:161702 pointer __p = this->__begin_ + (__first - begin());
Eric Fiselierfb342382016-12-28 06:06:091703 if (__first != __last) {
Howard Hinnantb4e67cf2013-04-18 15:02:571704 this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
Eric Fiselierfb342382016-12-28 06:06:091705 this->__invalidate_iterators_past(__p - 1);
1706 }
1707 iterator __r = __make_iter(__p);
Howard Hinnantbc8d3f92010-05-11 19:42:161708 return __r;
1709}
1710
1711template <class _Tp, class _Allocator>
1712void
1713vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1714{
1715 pointer __old_last = this->__end_;
1716 difference_type __n = __old_last - __to;
1717 for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1718 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191719 _VSTD::__to_raw_pointer(this->__end_),
1720 _VSTD::move(*__i));
1721 _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
Howard Hinnantbc8d3f92010-05-11 19:42:161722}
1723
1724template <class _Tp, class _Allocator>
1725typename vector<_Tp, _Allocator>::iterator
1726vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1727{
Howard Hinnantabe26282011-09-16 17:29:171728#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511729 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1730 "vector::insert(iterator, x) called with an iterator not"
1731 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171732#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161733 pointer __p = this->__begin_ + (__position - begin());
1734 if (this->__end_ < this->__end_cap())
1735 {
Kostya Serebryany497f9122014-09-02 23:43:381736 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:161737 if (__p == this->__end_)
1738 {
1739 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191740 _VSTD::__to_raw_pointer(this->__end_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161741 ++this->__end_;
1742 }
1743 else
1744 {
1745 __move_range(__p, this->__end_, __p + 1);
1746 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1747 if (__p <= __xr && __xr < this->__end_)
1748 ++__xr;
1749 *__p = *__xr;
1750 }
Kostya Serebryany497f9122014-09-02 23:43:381751 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:161752 }
1753 else
1754 {
1755 allocator_type& __a = this->__alloc();
1756 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1757 __v.push_back(__x);
1758 __p = __swap_out_circular_buffer(__v, __p);
1759 }
1760 return __make_iter(__p);
1761}
1762
Howard Hinnant73d21a42010-09-04 23:28:191763#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161764
1765template <class _Tp, class _Allocator>
1766typename vector<_Tp, _Allocator>::iterator
1767vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1768{
Howard Hinnantabe26282011-09-16 17:29:171769#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511770 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1771 "vector::insert(iterator, x) called with an iterator not"
1772 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171773#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161774 pointer __p = this->__begin_ + (__position - begin());
1775 if (this->__end_ < this->__end_cap())
1776 {
Kostya Serebryany497f9122014-09-02 23:43:381777 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:161778 if (__p == this->__end_)
1779 {
1780 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191781 _VSTD::__to_raw_pointer(this->__end_),
1782 _VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:161783 ++this->__end_;
1784 }
1785 else
1786 {
1787 __move_range(__p, this->__end_, __p + 1);
Howard Hinnant0949eed2011-06-30 21:18:191788 *__p = _VSTD::move(__x);
Howard Hinnantbc8d3f92010-05-11 19:42:161789 }
Kostya Serebryany497f9122014-09-02 23:43:381790 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:161791 }
1792 else
1793 {
1794 allocator_type& __a = this->__alloc();
1795 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:191796 __v.push_back(_VSTD::move(__x));
Howard Hinnantbc8d3f92010-05-11 19:42:161797 __p = __swap_out_circular_buffer(__v, __p);
1798 }
1799 return __make_iter(__p);
1800}
1801
Howard Hinnant73d21a42010-09-04 23:28:191802#ifndef _LIBCPP_HAS_NO_VARIADICS
1803
Howard Hinnantbc8d3f92010-05-11 19:42:161804template <class _Tp, class _Allocator>
1805template <class... _Args>
1806typename vector<_Tp, _Allocator>::iterator
1807vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1808{
Howard Hinnantabe26282011-09-16 17:29:171809#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511810 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1811 "vector::emplace(iterator, x) called with an iterator not"
1812 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171813#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161814 pointer __p = this->__begin_ + (__position - begin());
1815 if (this->__end_ < this->__end_cap())
1816 {
Kostya Serebryany497f9122014-09-02 23:43:381817 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:161818 if (__p == this->__end_)
1819 {
1820 __alloc_traits::construct(this->__alloc(),
Howard Hinnant0949eed2011-06-30 21:18:191821 _VSTD::__to_raw_pointer(this->__end_),
1822 _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161823 ++this->__end_;
1824 }
1825 else
1826 {
Marshall Clow51d7e8e2016-07-11 21:38:081827 __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161828 __move_range(__p, this->__end_, __p + 1);
Marshall Clow51d7e8e2016-07-11 21:38:081829 *__p = _VSTD::move(__tmp.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161830 }
Kostya Serebryany497f9122014-09-02 23:43:381831 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:161832 }
1833 else
1834 {
1835 allocator_type& __a = this->__alloc();
1836 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
Howard Hinnant0949eed2011-06-30 21:18:191837 __v.emplace_back(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161838 __p = __swap_out_circular_buffer(__v, __p);
1839 }
1840 return __make_iter(__p);
1841}
1842
Howard Hinnant73d21a42010-09-04 23:28:191843#endif // _LIBCPP_HAS_NO_VARIADICS
1844#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161845
1846template <class _Tp, class _Allocator>
1847typename vector<_Tp, _Allocator>::iterator
1848vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1849{
Howard Hinnantabe26282011-09-16 17:29:171850#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511851 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1852 "vector::insert(iterator, n, x) called with an iterator not"
1853 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171854#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161855 pointer __p = this->__begin_ + (__position - begin());
1856 if (__n > 0)
1857 {
1858 if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1859 {
1860 size_type __old_n = __n;
1861 pointer __old_last = this->__end_;
1862 if (__n > static_cast<size_type>(this->__end_ - __p))
1863 {
1864 size_type __cx = __n - (this->__end_ - __p);
1865 __construct_at_end(__cx, __x);
1866 __n -= __cx;
1867 }
1868 if (__n > 0)
1869 {
Eric Fiselierd7590952014-11-14 18:28:361870 __RAII_IncreaseAnnotator __annotator(*this, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161871 __move_range(__p, __old_last, __p + __old_n);
Kostya Serebryany497f9122014-09-02 23:43:381872 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:161873 const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1874 if (__p <= __xr && __xr < this->__end_)
1875 __xr += __old_n;
Howard Hinnant0949eed2011-06-30 21:18:191876 _VSTD::fill_n(__p, __n, *__xr);
Howard Hinnantbc8d3f92010-05-11 19:42:161877 }
1878 }
1879 else
1880 {
1881 allocator_type& __a = this->__alloc();
1882 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1883 __v.__construct_at_end(__n, __x);
1884 __p = __swap_out_circular_buffer(__v, __p);
1885 }
1886 }
1887 return __make_iter(__p);
1888}
1889
1890template <class _Tp, class _Allocator>
1891template <class _InputIterator>
1892typename enable_if
1893<
1894 __is_input_iterator <_InputIterator>::value &&
Howard Hinnant742fecb2013-03-28 17:44:321895 !__is_forward_iterator<_InputIterator>::value &&
1896 is_constructible<
1897 _Tp,
1898 typename iterator_traits<_InputIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161899 typename vector<_Tp, _Allocator>::iterator
1900>::type
1901vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1902{
Howard Hinnantabe26282011-09-16 17:29:171903#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511904 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1905 "vector::insert(iterator, range) called with an iterator not"
1906 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171907#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161908 difference_type __off = __position - begin();
1909 pointer __p = this->__begin_ + __off;
1910 allocator_type& __a = this->__alloc();
1911 pointer __old_last = this->__end_;
1912 for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1913 {
Eric Fiselier7d439a42015-07-18 18:22:121914 __RAII_IncreaseAnnotator __annotator(*this);
Howard Hinnant0949eed2011-06-30 21:18:191915 __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
Howard Hinnantbc8d3f92010-05-11 19:42:161916 *__first);
1917 ++this->__end_;
Eric Fiselier7d439a42015-07-18 18:22:121918 __annotator.__done();
Howard Hinnantbc8d3f92010-05-11 19:42:161919 }
1920 __split_buffer<value_type, allocator_type&> __v(__a);
1921 if (__first != __last)
1922 {
1923#ifndef _LIBCPP_NO_EXCEPTIONS
1924 try
1925 {
Howard Hinnant324bb032010-08-22 00:02:431926#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161927 __v.__construct_at_end(__first, __last);
1928 difference_type __old_size = __old_last - this->__begin_;
1929 difference_type __old_p = __p - this->__begin_;
1930 reserve(__recommend(size() + __v.size()));
1931 __p = this->__begin_ + __old_p;
1932 __old_last = this->__begin_ + __old_size;
1933#ifndef _LIBCPP_NO_EXCEPTIONS
1934 }
1935 catch (...)
1936 {
1937 erase(__make_iter(__old_last), end());
1938 throw;
1939 }
Howard Hinnant324bb032010-08-22 00:02:431940#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161941 }
Howard Hinnant0949eed2011-06-30 21:18:191942 __p = _VSTD::rotate(__p, __old_last, this->__end_);
Howard Hinnant0442b122011-09-16 18:41:291943 insert(__make_iter(__p), make_move_iterator(__v.begin()),
1944 make_move_iterator(__v.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161945 return begin() + __off;
1946}
1947
1948template <class _Tp, class _Allocator>
1949template <class _ForwardIterator>
1950typename enable_if
1951<
Howard Hinnant742fecb2013-03-28 17:44:321952 __is_forward_iterator<_ForwardIterator>::value &&
1953 is_constructible<
1954 _Tp,
1955 typename iterator_traits<_ForwardIterator>::reference>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161956 typename vector<_Tp, _Allocator>::iterator
1957>::type
1958vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1959{
Howard Hinnantabe26282011-09-16 17:29:171960#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:511961 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1962 "vector::insert(iterator, range) called with an iterator not"
1963 " referring to this vector");
Howard Hinnantabe26282011-09-16 17:29:171964#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161965 pointer __p = this->__begin_ + (__position - begin());
Howard Hinnant0949eed2011-06-30 21:18:191966 difference_type __n = _VSTD::distance(__first, __last);
Howard Hinnantbc8d3f92010-05-11 19:42:161967 if (__n > 0)
1968 {
1969 if (__n <= this->__end_cap() - this->__end_)
1970 {
1971 size_type __old_n = __n;
1972 pointer __old_last = this->__end_;
1973 _ForwardIterator __m = __last;
1974 difference_type __dx = this->__end_ - __p;
1975 if (__n > __dx)
1976 {
1977 __m = __first;
Eric Fiselier088ed9f2015-03-31 16:54:191978 difference_type __diff = this->__end_ - __p;
1979 _VSTD::advance(__m, __diff);
1980 __construct_at_end(__m, __last, __n - __diff);
Howard Hinnantbc8d3f92010-05-11 19:42:161981 __n = __dx;
1982 }
1983 if (__n > 0)
1984 {
Kostya Serebryany497f9122014-09-02 23:43:381985 __RAII_IncreaseAnnotator __annotator(*this, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161986 __move_range(__p, __old_last, __p + __old_n);
Kostya Serebryany497f9122014-09-02 23:43:381987 __annotator.__done();
Howard Hinnant0949eed2011-06-30 21:18:191988 _VSTD::copy(__first, __m, __p);
Howard Hinnantbc8d3f92010-05-11 19:42:161989 }
1990 }
1991 else
1992 {
1993 allocator_type& __a = this->__alloc();
1994 __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1995 __v.__construct_at_end(__first, __last);
1996 __p = __swap_out_circular_buffer(__v, __p);
1997 }
1998 }
1999 return __make_iter(__p);
2000}
2001
2002template <class _Tp, class _Allocator>
2003void
2004vector<_Tp, _Allocator>::resize(size_type __sz)
2005{
2006 size_type __cs = size();
2007 if (__cs < __sz)
2008 this->__append(__sz - __cs);
2009 else if (__cs > __sz)
2010 this->__destruct_at_end(this->__begin_ + __sz);
2011}
2012
2013template <class _Tp, class _Allocator>
2014void
2015vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
2016{
2017 size_type __cs = size();
2018 if (__cs < __sz)
2019 this->__append(__sz - __cs, __x);
2020 else if (__cs > __sz)
2021 this->__destruct_at_end(this->__begin_ + __sz);
2022}
2023
2024template <class _Tp, class _Allocator>
2025void
2026vector<_Tp, _Allocator>::swap(vector& __x)
Marshall Clow7d914d12015-07-13 20:04:562027#if _LIBCPP_STD_VER >= 14
Eric Fiselierfb342382016-12-28 06:06:092028 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:562029#else
Eric Fiselierfb342382016-12-28 06:06:092030 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:562031 __is_nothrow_swappable<allocator_type>::value)
2032#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162033{
Howard Hinnant7a563db2011-09-14 18:33:512034 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
2035 this->__alloc() == __x.__alloc(),
2036 "vector::swap: Either propagate_on_container_swap must be true"
2037 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:192038 _VSTD::swap(this->__begin_, __x.__begin_);
2039 _VSTD::swap(this->__end_, __x.__end_);
2040 _VSTD::swap(this->__end_cap(), __x.__end_cap());
Marshall Clow7d914d12015-07-13 20:04:562041 __swap_allocator(this->__alloc(), __x.__alloc(),
2042 integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
Howard Hinnantabe26282011-09-16 17:29:172043#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:512044 __get_db()->swap(this, &__x);
Howard Hinnantabe26282011-09-16 17:29:172045#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:162046}
2047
Howard Hinnant324bb032010-08-22 00:02:432048template <class _Tp, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162049bool
2050vector<_Tp, _Allocator>::__invariants() const
2051{
Howard Hinnant2c39cbe2013-06-27 19:35:322052 if (this->__begin_ == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162053 {
Howard Hinnant2c39cbe2013-06-27 19:35:322054 if (this->__end_ != nullptr || this->__end_cap() != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162055 return false;
2056 }
2057 else
2058 {
2059 if (this->__begin_ > this->__end_)
2060 return false;
2061 if (this->__begin_ == this->__end_cap())
2062 return false;
2063 if (this->__end_ > this->__end_cap())
2064 return false;
2065 }
2066 return true;
2067}
2068
Howard Hinnantabe26282011-09-16 17:29:172069#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:512070
Howard Hinnantbc8d3f92010-05-11 19:42:162071template <class _Tp, class _Allocator>
Howard Hinnant7a563db2011-09-14 18:33:512072bool
2073vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
2074{
2075 return this->__begin_ <= __i->base() && __i->base() < this->__end_;
2076}
2077
2078template <class _Tp, class _Allocator>
2079bool
2080vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
2081{
2082 return this->__begin_ < __i->base() && __i->base() <= this->__end_;
2083}
2084
2085template <class _Tp, class _Allocator>
2086bool
2087vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2088{
2089 const_pointer __p = __i->base() + __n;
2090 return this->__begin_ <= __p && __p <= this->__end_;
2091}
2092
2093template <class _Tp, class _Allocator>
2094bool
2095vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2096{
2097 const_pointer __p = __i->base() + __n;
2098 return this->__begin_ <= __p && __p < this->__end_;
2099}
2100
Howard Hinnantabe26282011-09-16 17:29:172101#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:512102
2103template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002104inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162105void
2106vector<_Tp, _Allocator>::__invalidate_all_iterators()
2107{
Howard Hinnantabe26282011-09-16 17:29:172108#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant7a563db2011-09-14 18:33:512109 __get_db()->__invalidate_all(this);
Howard Hinnantabe26282011-09-16 17:29:172110#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:162111}
2112
Eric Fiselierfb342382016-12-28 06:06:092113
2114template <class _Tp, class _Allocator>
2115inline _LIBCPP_INLINE_VISIBILITY
2116void
2117vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
2118#if _LIBCPP_DEBUG_LEVEL >= 2
2119 __c_node* __c = __get_db()->__find_c_and_lock(this);
2120 for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
2121 --__p;
2122 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
2123 if (__i->base() > __new_last) {
2124 (*__p)->__c_ = nullptr;
2125 if (--__c->end_ != __p)
2126 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
2127 }
2128 }
2129 __get_db()->unlock();
2130#else
2131 ((void)__new_last);
2132#endif
2133}
2134
Howard Hinnantbc8d3f92010-05-11 19:42:162135// vector<bool>
2136
2137template <class _Allocator> class vector<bool, _Allocator>;
2138
2139template <class _Allocator> struct hash<vector<bool, _Allocator> >;
2140
2141template <class _Allocator>
Howard Hinnantf03c3b42011-07-02 20:33:232142struct __has_storage_type<vector<bool, _Allocator> >
2143{
2144 static const bool value = true;
2145};
2146
2147template <class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:002148class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162149 : private __vector_base_common<true>
2150{
2151public:
2152 typedef vector __self;
Howard Hinnant324bb032010-08-22 00:02:432153 typedef bool value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:162154 typedef _Allocator allocator_type;
2155 typedef allocator_traits<allocator_type> __alloc_traits;
Howard Hinnantbc8d3f92010-05-11 19:42:162156 typedef typename __alloc_traits::size_type size_type;
2157 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnantf867f632012-05-07 16:50:382158 typedef size_type __storage_type;
Howard Hinnantbc8d3f92010-05-11 19:42:162159 typedef __bit_iterator<vector, false> pointer;
2160 typedef __bit_iterator<vector, true> const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:162161 typedef pointer iterator;
2162 typedef const_pointer const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:192163 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
2164 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:162165
2166private:
Marshall Clow66302c62015-04-07 05:21:382167 typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
Howard Hinnantbc8d3f92010-05-11 19:42:162168 typedef allocator_traits<__storage_allocator> __storage_traits;
2169 typedef typename __storage_traits::pointer __storage_pointer;
2170 typedef typename __storage_traits::const_pointer __const_storage_pointer;
2171
2172 __storage_pointer __begin_;
2173 size_type __size_;
2174 __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
Howard Hinnant2bf1c082011-07-09 15:50:422175public:
Howard Hinnantf03c3b42011-07-02 20:33:232176 typedef __bit_reference<vector> reference;
2177 typedef __bit_const_reference<vector> const_reference;
Howard Hinnant2bf1c082011-07-09 15:50:422178private:
Howard Hinnantd1d27a42011-06-03 19:40:402179 _LIBCPP_INLINE_VISIBILITY
2180 size_type& __cap() _NOEXCEPT
2181 {return __cap_alloc_.first();}
2182 _LIBCPP_INLINE_VISIBILITY
2183 const size_type& __cap() const _NOEXCEPT
2184 {return __cap_alloc_.first();}
2185 _LIBCPP_INLINE_VISIBILITY
2186 __storage_allocator& __alloc() _NOEXCEPT
2187 {return __cap_alloc_.second();}
2188 _LIBCPP_INLINE_VISIBILITY
2189 const __storage_allocator& __alloc() const _NOEXCEPT
2190 {return __cap_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:162191
2192 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2193
Howard Hinnantd1d27a42011-06-03 19:40:402194 _LIBCPP_INLINE_VISIBILITY
2195 static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162196 {return __n * __bits_per_word;}
Howard Hinnantd1d27a42011-06-03 19:40:402197 _LIBCPP_INLINE_VISIBILITY
2198 static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162199 {return (__n - 1) / __bits_per_word + 1;}
2200
2201public:
Howard Hinnantd1d27a42011-06-03 19:40:402202 _LIBCPP_INLINE_VISIBILITY
Marshall Clowc912c0c2015-06-04 02:05:412203 vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow127db912015-06-04 00:10:202204
2205 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
2206#if _LIBCPP_STD_VER <= 14
2207 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
2208#else
2209 _NOEXCEPT;
2210#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162211 ~vector();
2212 explicit vector(size_type __n);
Marshall Clowa49a2c92013-09-14 00:47:592213#if _LIBCPP_STD_VER > 11
2214 explicit vector(size_type __n, const allocator_type& __a);
2215#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162216 vector(size_type __n, const value_type& __v);
2217 vector(size_type __n, const value_type& __v, const allocator_type& __a);
2218 template <class _InputIterator>
2219 vector(_InputIterator __first, _InputIterator __last,
2220 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2221 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2222 template <class _InputIterator>
2223 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2224 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2225 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2226 template <class _ForwardIterator>
2227 vector(_ForwardIterator __first, _ForwardIterator __last,
2228 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2229 template <class _ForwardIterator>
2230 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2231 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2232
2233 vector(const vector& __v);
2234 vector(const vector& __v, const allocator_type& __a);
2235 vector& operator=(const vector& __v);
Howard Hinnante3e32912011-08-12 21:56:022236#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:162237 vector(initializer_list<value_type> __il);
2238 vector(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:022239#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:162240
Howard Hinnant73d21a42010-09-04 23:28:192241#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantd1d27a42011-06-03 19:40:402242 _LIBCPP_INLINE_VISIBILITY
2243 vector(vector&& __v)
Marshall Clow119ed472015-07-14 14:46:322244#if _LIBCPP_STD_VER > 14
2245 _NOEXCEPT;
2246#else
Howard Hinnantd1d27a42011-06-03 19:40:402247 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow119ed472015-07-14 14:46:322248#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162249 vector(vector&& __v, const allocator_type& __a);
Howard Hinnantd1d27a42011-06-03 19:40:402250 _LIBCPP_INLINE_VISIBILITY
2251 vector& operator=(vector&& __v)
Marshall Clowaf961ed2015-08-18 18:57:002252 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnant73d21a42010-09-04 23:28:192253#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:022254#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:282255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162256 vector& operator=(initializer_list<value_type> __il)
2257 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:022258#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:162259
2260 template <class _InputIterator>
2261 typename enable_if
2262 <
2263 __is_input_iterator<_InputIterator>::value &&
2264 !__is_forward_iterator<_InputIterator>::value,
2265 void
2266 >::type
2267 assign(_InputIterator __first, _InputIterator __last);
2268 template <class _ForwardIterator>
2269 typename enable_if
2270 <
2271 __is_forward_iterator<_ForwardIterator>::value,
2272 void
2273 >::type
2274 assign(_ForwardIterator __first, _ForwardIterator __last);
2275
2276 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:022277#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:282278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162279 void assign(initializer_list<value_type> __il)
2280 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:022281#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:162282
Howard Hinnantd1d27a42011-06-03 19:40:402283 _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162284 {return allocator_type(this->__alloc());}
2285
Howard Hinnantd1d27a42011-06-03 19:40:402286 size_type max_size() const _NOEXCEPT;
2287 _LIBCPP_INLINE_VISIBILITY
2288 size_type capacity() const _NOEXCEPT
2289 {return __internal_cap_to_external(__cap());}
2290 _LIBCPP_INLINE_VISIBILITY
2291 size_type size() const _NOEXCEPT
2292 {return __size_;}
2293 _LIBCPP_INLINE_VISIBILITY
2294 bool empty() const _NOEXCEPT
2295 {return __size_ == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:162296 void reserve(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:402297 void shrink_to_fit() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:162298
Howard Hinnantd1d27a42011-06-03 19:40:402299 _LIBCPP_INLINE_VISIBILITY
2300 iterator begin() _NOEXCEPT
2301 {return __make_iter(0);}
2302 _LIBCPP_INLINE_VISIBILITY
2303 const_iterator begin() const _NOEXCEPT
2304 {return __make_iter(0);}
2305 _LIBCPP_INLINE_VISIBILITY
2306 iterator end() _NOEXCEPT
2307 {return __make_iter(__size_);}
2308 _LIBCPP_INLINE_VISIBILITY
2309 const_iterator end() const _NOEXCEPT
2310 {return __make_iter(__size_);}
Howard Hinnantbc8d3f92010-05-11 19:42:162311
Howard Hinnantd1d27a42011-06-03 19:40:402312 _LIBCPP_INLINE_VISIBILITY
2313 reverse_iterator rbegin() _NOEXCEPT
2314 {return reverse_iterator(end());}
2315 _LIBCPP_INLINE_VISIBILITY
2316 const_reverse_iterator rbegin() const _NOEXCEPT
2317 {return const_reverse_iterator(end());}
2318 _LIBCPP_INLINE_VISIBILITY
2319 reverse_iterator rend() _NOEXCEPT
2320 {return reverse_iterator(begin());}
2321 _LIBCPP_INLINE_VISIBILITY
2322 const_reverse_iterator rend() const _NOEXCEPT
2323 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:162324
Howard Hinnantd1d27a42011-06-03 19:40:402325 _LIBCPP_INLINE_VISIBILITY
2326 const_iterator cbegin() const _NOEXCEPT
2327 {return __make_iter(0);}
2328 _LIBCPP_INLINE_VISIBILITY
2329 const_iterator cend() const _NOEXCEPT
2330 {return __make_iter(__size_);}
2331 _LIBCPP_INLINE_VISIBILITY
2332 const_reverse_iterator crbegin() const _NOEXCEPT
2333 {return rbegin();}
2334 _LIBCPP_INLINE_VISIBILITY
2335 const_reverse_iterator crend() const _NOEXCEPT
2336 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:162337
2338 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
2339 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2340 reference at(size_type __n);
2341 const_reference at(size_type __n) const;
2342
2343 _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
2344 _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2345 _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
2346 _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
2347
2348 void push_back(const value_type& __x);
Marshall Clow198a2a52013-08-13 23:54:122349#if _LIBCPP_STD_VER > 11
2350 template <class... _Args>
Marshall Clow4e42dc92017-01-24 23:09:122351#if _LIBCPP_STD_VER > 14
2352 _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args)
2353#else
2354 _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
2355#endif
2356 {
Eric Fiselier3816ef92016-07-21 03:20:172357 push_back ( value_type ( _VSTD::forward<_Args>(__args)... ));
Marshall Clow4e42dc92017-01-24 23:09:122358#if _LIBCPP_STD_VER > 14
Eric Fiselier3816ef92016-07-21 03:20:172359 return this->back();
Marshall Clow4e42dc92017-01-24 23:09:122360#endif
Eric Fiselier3816ef92016-07-21 03:20:172361 }
Marshall Clow198a2a52013-08-13 23:54:122362#endif
2363
Howard Hinnantbc8d3f92010-05-11 19:42:162364 _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2365
Marshall Clow198a2a52013-08-13 23:54:122366#if _LIBCPP_STD_VER > 11
2367 template <class... _Args>
2368 _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
2369 { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
2370#endif
2371
Howard Hinnantbc8d3f92010-05-11 19:42:162372 iterator insert(const_iterator __position, const value_type& __x);
2373 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2374 iterator insert(const_iterator __position, size_type __n, const_reference __x);
2375 template <class _InputIterator>
2376 typename enable_if
2377 <
2378 __is_input_iterator <_InputIterator>::value &&
2379 !__is_forward_iterator<_InputIterator>::value,
2380 iterator
2381 >::type
2382 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2383 template <class _ForwardIterator>
2384 typename enable_if
2385 <
2386 __is_forward_iterator<_ForwardIterator>::value,
2387 iterator
2388 >::type
2389 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:022390#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:282391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162392 iterator insert(const_iterator __position, initializer_list<value_type> __il)
2393 {return insert(__position, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:022394#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:162395
Howard Hinnant2d72b1e2010-12-17 14:46:432396 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
Howard Hinnantbc8d3f92010-05-11 19:42:162397 iterator erase(const_iterator __first, const_iterator __last);
2398
Howard Hinnantd1d27a42011-06-03 19:40:402399 _LIBCPP_INLINE_VISIBILITY
2400 void clear() _NOEXCEPT {__size_ = 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:162401
Howard Hinnantd1d27a42011-06-03 19:40:402402 void swap(vector&)
Marshall Clow7d914d12015-07-13 20:04:562403#if _LIBCPP_STD_VER >= 14
2404 _NOEXCEPT;
2405#else
Eric Fiselierfb342382016-12-28 06:06:092406 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:562407 __is_nothrow_swappable<allocator_type>::value);
2408#endif
Marshall Clow005c60b2016-04-07 14:20:312409 static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
Howard Hinnantbc8d3f92010-05-11 19:42:162410
2411 void resize(size_type __sz, value_type __x = false);
Howard Hinnantd1d27a42011-06-03 19:40:402412 void flip() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:162413
2414 bool __invariants() const;
2415
2416private:
Howard Hinnant2d72b1e2010-12-17 14:46:432417 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:162418 void allocate(size_type __n);
Howard Hinnantd1d27a42011-06-03 19:40:402419 void deallocate() _NOEXCEPT;
2420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:202421 static size_type __align_it(size_type __new_size) _NOEXCEPT
Marshall Clow0d1965d2014-07-28 15:02:422422 {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);};
Howard Hinnant2d72b1e2010-12-17 14:46:432423 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
2424 _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
Howard Hinnantbc8d3f92010-05-11 19:42:162425 template <class _ForwardIterator>
2426 typename enable_if
2427 <
2428 __is_forward_iterator<_ForwardIterator>::value,
2429 void
2430 >::type
2431 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2432 void __append(size_type __n, const_reference __x);
Howard Hinnantd1d27a42011-06-03 19:40:402433 _LIBCPP_INLINE_VISIBILITY
2434 reference __make_ref(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162435 {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:402436 _LIBCPP_INLINE_VISIBILITY
2437 const_reference __make_ref(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162438 {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnantd1d27a42011-06-03 19:40:402439 _LIBCPP_INLINE_VISIBILITY
2440 iterator __make_iter(size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162441 {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:402442 _LIBCPP_INLINE_VISIBILITY
2443 const_iterator __make_iter(size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162444 {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
Howard Hinnantd1d27a42011-06-03 19:40:402445 _LIBCPP_INLINE_VISIBILITY
2446 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
Howard Hinnant2c39cbe2013-06-27 19:35:322447 {return begin() + (__p - cbegin());}
Howard Hinnantbc8d3f92010-05-11 19:42:162448
Howard Hinnantee6ccd02010-09-23 18:58:282449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162450 void __copy_assign_alloc(const vector& __v)
2451 {__copy_assign_alloc(__v, integral_constant<bool,
2452 __storage_traits::propagate_on_container_copy_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:282453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162454 void __copy_assign_alloc(const vector& __c, true_type)
2455 {
2456 if (__alloc() != __c.__alloc())
2457 deallocate();
2458 __alloc() = __c.__alloc();
2459 }
2460
Howard Hinnantee6ccd02010-09-23 18:58:282461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:042462 void __copy_assign_alloc(const vector&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:162463 {}
2464
2465 void __move_assign(vector& __c, false_type);
Howard Hinnantd1d27a42011-06-03 19:40:402466 void __move_assign(vector& __c, true_type)
2467 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantee6ccd02010-09-23 18:58:282468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162469 void __move_assign_alloc(vector& __c)
Howard Hinnantd1d27a42011-06-03 19:40:402470 _NOEXCEPT_(
2471 !__storage_traits::propagate_on_container_move_assignment::value ||
2472 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:162473 {__move_assign_alloc(__c, integral_constant<bool,
2474 __storage_traits::propagate_on_container_move_assignment::value>());}
Howard Hinnantee6ccd02010-09-23 18:58:282475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:312476 void __move_assign_alloc(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:402477 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:162478 {
Howard Hinnant0949eed2011-06-30 21:18:192479 __alloc() = _VSTD::move(__c.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:162480 }
2481
Howard Hinnantee6ccd02010-09-23 18:58:282482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:042483 void __move_assign_alloc(vector&, false_type)
Howard Hinnantd1d27a42011-06-03 19:40:402484 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162485 {}
2486
Howard Hinnantd1d27a42011-06-03 19:40:402487 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:162488
2489 friend class __bit_reference<vector>;
2490 friend class __bit_const_reference<vector>;
2491 friend class __bit_iterator<vector, false>;
2492 friend class __bit_iterator<vector, true>;
Howard Hinnant4ae952a2012-08-17 17:10:182493 friend struct __bit_array<vector>;
Eric Fiselierc3589a82017-01-04 23:56:002494 friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
Howard Hinnantbc8d3f92010-05-11 19:42:162495};
2496
2497template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002498inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162499void
2500vector<bool, _Allocator>::__invalidate_all_iterators()
2501{
Howard Hinnantbc8d3f92010-05-11 19:42:162502}
2503
2504// Allocate space for __n objects
2505// throws length_error if __n > max_size()
2506// throws (probably bad_alloc) if memory run out
2507// Precondition: __begin_ == __end_ == __cap() == 0
2508// Precondition: __n > 0
2509// Postcondition: capacity() == __n
2510// Postcondition: size() == 0
2511template <class _Allocator>
2512void
2513vector<bool, _Allocator>::allocate(size_type __n)
2514{
2515 if (__n > max_size())
2516 this->__throw_length_error();
2517 __n = __external_cap_to_internal(__n);
2518 this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2519 this->__size_ = 0;
2520 this->__cap() = __n;
2521}
2522
2523template <class _Allocator>
2524void
Howard Hinnantd1d27a42011-06-03 19:40:402525vector<bool, _Allocator>::deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162526{
Howard Hinnant2c39cbe2013-06-27 19:35:322527 if (this->__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162528 {
2529 __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2530 __invalidate_all_iterators();
Howard Hinnant2c39cbe2013-06-27 19:35:322531 this->__begin_ = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:162532 this->__size_ = this->__cap() = 0;
2533 }
2534}
2535
2536template <class _Allocator>
2537typename vector<bool, _Allocator>::size_type
Howard Hinnantd1d27a42011-06-03 19:40:402538vector<bool, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162539{
2540 size_type __amax = __storage_traits::max_size(__alloc());
2541 size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
2542 if (__nmax / __bits_per_word <= __amax)
2543 return __nmax;
2544 return __internal_cap_to_external(__amax);
2545}
2546
2547// Precondition: __new_size > capacity()
2548template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002549inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162550typename vector<bool, _Allocator>::size_type
2551vector<bool, _Allocator>::__recommend(size_type __new_size) const
2552{
2553 const size_type __ms = max_size();
2554 if (__new_size > __ms)
2555 this->__throw_length_error();
2556 const size_type __cap = capacity();
2557 if (__cap >= __ms / 2)
2558 return __ms;
Howard Hinnant7f764502013-08-14 18:00:202559 return _VSTD::max(2*__cap, __align_it(__new_size));
Howard Hinnantbc8d3f92010-05-11 19:42:162560}
2561
2562// Default constructs __n objects starting at __end_
2563// Precondition: __n > 0
2564// Precondition: size() + __n <= capacity()
2565// Postcondition: size() == size() + __n
2566template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002567inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162568void
2569vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2570{
2571 size_type __old_size = this->__size_;
2572 this->__size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:192573 _VSTD::fill_n(__make_iter(__old_size), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:162574}
2575
2576template <class _Allocator>
2577template <class _ForwardIterator>
2578typename enable_if
2579<
2580 __is_forward_iterator<_ForwardIterator>::value,
2581 void
2582>::type
2583vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2584{
2585 size_type __old_size = this->__size_;
Howard Hinnant0949eed2011-06-30 21:18:192586 this->__size_ += _VSTD::distance(__first, __last);
2587 _VSTD::copy(__first, __last, __make_iter(__old_size));
Howard Hinnantbc8d3f92010-05-11 19:42:162588}
2589
2590template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002591inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162592vector<bool, _Allocator>::vector()
Marshall Clowc912c0c2015-06-04 02:05:412593 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnant2c39cbe2013-06-27 19:35:322594 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162595 __size_(0),
2596 __cap_alloc_(0)
2597{
2598}
2599
2600template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002601inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162602vector<bool, _Allocator>::vector(const allocator_type& __a)
Marshall Clow127db912015-06-04 00:10:202603#if _LIBCPP_STD_VER <= 14
2604 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
2605#else
2606 _NOEXCEPT
2607#endif
Howard Hinnant2c39cbe2013-06-27 19:35:322608 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162609 __size_(0),
2610 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2611{
2612}
2613
2614template <class _Allocator>
2615vector<bool, _Allocator>::vector(size_type __n)
Howard Hinnant2c39cbe2013-06-27 19:35:322616 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162617 __size_(0),
2618 __cap_alloc_(0)
2619{
2620 if (__n > 0)
2621 {
2622 allocate(__n);
2623 __construct_at_end(__n, false);
2624 }
2625}
2626
Marshall Clowa49a2c92013-09-14 00:47:592627#if _LIBCPP_STD_VER > 11
2628template <class _Allocator>
2629vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2630 : __begin_(nullptr),
2631 __size_(0),
2632 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2633{
2634 if (__n > 0)
2635 {
2636 allocate(__n);
2637 __construct_at_end(__n, false);
2638 }
2639}
2640#endif
2641
Howard Hinnantbc8d3f92010-05-11 19:42:162642template <class _Allocator>
2643vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
Howard Hinnant2c39cbe2013-06-27 19:35:322644 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162645 __size_(0),
2646 __cap_alloc_(0)
2647{
2648 if (__n > 0)
2649 {
2650 allocate(__n);
2651 __construct_at_end(__n, __x);
2652 }
2653}
2654
2655template <class _Allocator>
2656vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:322657 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162658 __size_(0),
2659 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2660{
2661 if (__n > 0)
2662 {
2663 allocate(__n);
2664 __construct_at_end(__n, __x);
2665 }
2666}
2667
2668template <class _Allocator>
2669template <class _InputIterator>
2670vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2671 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2672 !__is_forward_iterator<_InputIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:322673 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162674 __size_(0),
2675 __cap_alloc_(0)
2676{
2677#ifndef _LIBCPP_NO_EXCEPTIONS
2678 try
2679 {
Howard Hinnant324bb032010-08-22 00:02:432680#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162681 for (; __first != __last; ++__first)
2682 push_back(*__first);
2683#ifndef _LIBCPP_NO_EXCEPTIONS
2684 }
2685 catch (...)
2686 {
Howard Hinnant2c39cbe2013-06-27 19:35:322687 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162688 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2689 __invalidate_all_iterators();
2690 throw;
2691 }
Howard Hinnant324bb032010-08-22 00:02:432692#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162693}
2694
2695template <class _Allocator>
2696template <class _InputIterator>
2697vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2698 typename enable_if<__is_input_iterator <_InputIterator>::value &&
2699 !__is_forward_iterator<_InputIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:322700 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162701 __size_(0),
2702 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2703{
2704#ifndef _LIBCPP_NO_EXCEPTIONS
2705 try
2706 {
Howard Hinnant324bb032010-08-22 00:02:432707#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162708 for (; __first != __last; ++__first)
2709 push_back(*__first);
2710#ifndef _LIBCPP_NO_EXCEPTIONS
2711 }
2712 catch (...)
2713 {
Howard Hinnant2c39cbe2013-06-27 19:35:322714 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162715 __storage_traits::deallocate(__alloc(), __begin_, __cap());
2716 __invalidate_all_iterators();
2717 throw;
2718 }
Howard Hinnant324bb032010-08-22 00:02:432719#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:162720}
2721
2722template <class _Allocator>
2723template <class _ForwardIterator>
2724vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2725 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:322726 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162727 __size_(0),
2728 __cap_alloc_(0)
2729{
Howard Hinnant0949eed2011-06-30 21:18:192730 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:162731 if (__n > 0)
2732 {
2733 allocate(__n);
2734 __construct_at_end(__first, __last);
2735 }
2736}
2737
2738template <class _Allocator>
2739template <class _ForwardIterator>
2740vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2741 typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
Howard Hinnant2c39cbe2013-06-27 19:35:322742 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162743 __size_(0),
2744 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2745{
Howard Hinnant0949eed2011-06-30 21:18:192746 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:162747 if (__n > 0)
2748 {
2749 allocate(__n);
2750 __construct_at_end(__first, __last);
2751 }
2752}
2753
Howard Hinnante3e32912011-08-12 21:56:022754#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2755
Howard Hinnantbc8d3f92010-05-11 19:42:162756template <class _Allocator>
2757vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
Howard Hinnant2c39cbe2013-06-27 19:35:322758 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162759 __size_(0),
2760 __cap_alloc_(0)
2761{
2762 size_type __n = static_cast<size_type>(__il.size());
2763 if (__n > 0)
2764 {
2765 allocate(__n);
2766 __construct_at_end(__il.begin(), __il.end());
2767 }
2768}
2769
2770template <class _Allocator>
2771vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:322772 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162773 __size_(0),
2774 __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2775{
2776 size_type __n = static_cast<size_type>(__il.size());
2777 if (__n > 0)
2778 {
2779 allocate(__n);
2780 __construct_at_end(__il.begin(), __il.end());
2781 }
2782}
2783
Howard Hinnante3e32912011-08-12 21:56:022784#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2785
Howard Hinnantbc8d3f92010-05-11 19:42:162786template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:162787vector<bool, _Allocator>::~vector()
2788{
Howard Hinnant2c39cbe2013-06-27 19:35:322789 if (__begin_ != nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:162790 __storage_traits::deallocate(__alloc(), __begin_, __cap());
Howard Hinnantbc8d3f92010-05-11 19:42:162791 __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:162792}
2793
2794template <class _Allocator>
2795vector<bool, _Allocator>::vector(const vector& __v)
Howard Hinnant2c39cbe2013-06-27 19:35:322796 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162797 __size_(0),
2798 __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2799{
2800 if (__v.size() > 0)
2801 {
2802 allocate(__v.size());
2803 __construct_at_end(__v.begin(), __v.end());
2804 }
2805}
2806
2807template <class _Allocator>
2808vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:322809 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162810 __size_(0),
2811 __cap_alloc_(0, __a)
2812{
2813 if (__v.size() > 0)
2814 {
2815 allocate(__v.size());
2816 __construct_at_end(__v.begin(), __v.end());
2817 }
2818}
2819
2820template <class _Allocator>
2821vector<bool, _Allocator>&
2822vector<bool, _Allocator>::operator=(const vector& __v)
2823{
2824 if (this != &__v)
2825 {
2826 __copy_assign_alloc(__v);
2827 if (__v.__size_)
2828 {
2829 if (__v.__size_ > capacity())
2830 {
2831 deallocate();
2832 allocate(__v.__size_);
2833 }
Howard Hinnant0949eed2011-06-30 21:18:192834 _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
Howard Hinnantbc8d3f92010-05-11 19:42:162835 }
2836 __size_ = __v.__size_;
2837 }
2838 return *this;
2839}
2840
Howard Hinnant73d21a42010-09-04 23:28:192841#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2842
Howard Hinnantbc8d3f92010-05-11 19:42:162843template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002844inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162845vector<bool, _Allocator>::vector(vector&& __v)
Marshall Clow119ed472015-07-14 14:46:322846#if _LIBCPP_STD_VER > 14
2847 _NOEXCEPT
2848#else
Howard Hinnantd1d27a42011-06-03 19:40:402849 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow119ed472015-07-14 14:46:322850#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162851 : __begin_(__v.__begin_),
2852 __size_(__v.__size_),
2853 __cap_alloc_(__v.__cap_alloc_)
2854{
Howard Hinnant2c39cbe2013-06-27 19:35:322855 __v.__begin_ = nullptr;
Howard Hinnantbc8d3f92010-05-11 19:42:162856 __v.__size_ = 0;
2857 __v.__cap() = 0;
2858}
2859
2860template <class _Allocator>
2861vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
Howard Hinnant2c39cbe2013-06-27 19:35:322862 : __begin_(nullptr),
Howard Hinnantbc8d3f92010-05-11 19:42:162863 __size_(0),
2864 __cap_alloc_(0, __a)
2865{
2866 if (__a == allocator_type(__v.__alloc()))
2867 {
2868 this->__begin_ = __v.__begin_;
2869 this->__size_ = __v.__size_;
2870 this->__cap() = __v.__cap();
2871 __v.__begin_ = nullptr;
2872 __v.__cap() = __v.__size_ = 0;
2873 }
2874 else if (__v.size() > 0)
2875 {
2876 allocate(__v.size());
2877 __construct_at_end(__v.begin(), __v.end());
2878 }
2879}
2880
2881template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:002882inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162883vector<bool, _Allocator>&
2884vector<bool, _Allocator>::operator=(vector&& __v)
Marshall Clowaf961ed2015-08-18 18:57:002885 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnantbc8d3f92010-05-11 19:42:162886{
2887 __move_assign(__v, integral_constant<bool,
2888 __storage_traits::propagate_on_container_move_assignment::value>());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:452889 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:162890}
2891
2892template <class _Allocator>
2893void
2894vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2895{
2896 if (__alloc() != __c.__alloc())
2897 assign(__c.begin(), __c.end());
2898 else
2899 __move_assign(__c, true_type());
2900}
2901
2902template <class _Allocator>
2903void
2904vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
Howard Hinnantd1d27a42011-06-03 19:40:402905 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:162906{
2907 deallocate();
Marshall Clowdb5e54d2014-07-21 15:15:152908 __move_assign_alloc(__c);
Howard Hinnantbc8d3f92010-05-11 19:42:162909 this->__begin_ = __c.__begin_;
2910 this->__size_ = __c.__size_;
2911 this->__cap() = __c.__cap();
Howard Hinnantbc8d3f92010-05-11 19:42:162912 __c.__begin_ = nullptr;
2913 __c.__cap() = __c.__size_ = 0;
2914}
Howard Hinnant73d21a42010-09-04 23:28:192915
2916#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:162917
2918template <class _Allocator>
2919void
2920vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2921{
2922 __size_ = 0;
2923 if (__n > 0)
2924 {
2925 size_type __c = capacity();
2926 if (__n <= __c)
2927 __size_ = __n;
2928 else
2929 {
2930 vector __v(__alloc());
2931 __v.reserve(__recommend(__n));
2932 __v.__size_ = __n;
2933 swap(__v);
2934 }
Howard Hinnant0949eed2011-06-30 21:18:192935 _VSTD::fill_n(begin(), __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:162936 }
Eric Fiselierfb342382016-12-28 06:06:092937 __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:162938}
2939
2940template <class _Allocator>
2941template <class _InputIterator>
2942typename enable_if
2943<
2944 __is_input_iterator<_InputIterator>::value &&
2945 !__is_forward_iterator<_InputIterator>::value,
2946 void
2947>::type
2948vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2949{
2950 clear();
2951 for (; __first != __last; ++__first)
2952 push_back(*__first);
2953}
2954
2955template <class _Allocator>
2956template <class _ForwardIterator>
2957typename enable_if
2958<
2959 __is_forward_iterator<_ForwardIterator>::value,
2960 void
2961>::type
2962vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2963{
2964 clear();
Eric Fiselier0e5ebbc2016-12-23 23:37:522965 difference_type __ns = _VSTD::distance(__first, __last);
2966 _LIBCPP_ASSERT(__ns >= 0, "invalid range specified");
2967 const size_t __n = static_cast<size_type>(__ns);
Howard Hinnantbc8d3f92010-05-11 19:42:162968 if (__n)
2969 {
2970 if (__n > capacity())
2971 {
2972 deallocate();
2973 allocate(__n);
2974 }
2975 __construct_at_end(__first, __last);
2976 }
2977}
2978
2979template <class _Allocator>
2980void
2981vector<bool, _Allocator>::reserve(size_type __n)
2982{
2983 if (__n > capacity())
2984 {
2985 vector __v(this->__alloc());
2986 __v.allocate(__n);
2987 __v.__construct_at_end(this->begin(), this->end());
2988 swap(__v);
2989 __invalidate_all_iterators();
2990 }
2991}
2992
2993template <class _Allocator>
2994void
Howard Hinnantd1d27a42011-06-03 19:40:402995vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162996{
2997 if (__external_cap_to_internal(size()) > __cap())
2998 {
2999#ifndef _LIBCPP_NO_EXCEPTIONS
3000 try
3001 {
Howard Hinnant324bb032010-08-22 00:02:433002#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:163003 vector(*this, allocator_type(__alloc())).swap(*this);
3004#ifndef _LIBCPP_NO_EXCEPTIONS
3005 }
3006 catch (...)
3007 {
3008 }
Howard Hinnant324bb032010-08-22 00:02:433009#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:163010 }
3011}
3012
3013template <class _Allocator>
3014typename vector<bool, _Allocator>::reference
3015vector<bool, _Allocator>::at(size_type __n)
3016{
3017 if (__n >= size())
3018 this->__throw_out_of_range();
3019 return (*this)[__n];
3020}
3021
3022template <class _Allocator>
3023typename vector<bool, _Allocator>::const_reference
3024vector<bool, _Allocator>::at(size_type __n) const
3025{
3026 if (__n >= size())
3027 this->__throw_out_of_range();
3028 return (*this)[__n];
3029}
3030
3031template <class _Allocator>
3032void
3033vector<bool, _Allocator>::push_back(const value_type& __x)
3034{
3035 if (this->__size_ == this->capacity())
3036 reserve(__recommend(this->__size_ + 1));
3037 ++this->__size_;
3038 back() = __x;
3039}
3040
3041template <class _Allocator>
3042typename vector<bool, _Allocator>::iterator
3043vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
3044{
3045 iterator __r;
3046 if (size() < capacity())
3047 {
3048 const_iterator __old_end = end();
3049 ++__size_;
Howard Hinnant0949eed2011-06-30 21:18:193050 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:163051 __r = __const_iterator_cast(__position);
3052 }
3053 else
3054 {
3055 vector __v(__alloc());
3056 __v.reserve(__recommend(__size_ + 1));
3057 __v.__size_ = __size_ + 1;
Howard Hinnant0949eed2011-06-30 21:18:193058 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3059 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:163060 swap(__v);
3061 }
3062 *__r = __x;
3063 return __r;
3064}
3065
3066template <class _Allocator>
3067typename vector<bool, _Allocator>::iterator
3068vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
3069{
3070 iterator __r;
3071 size_type __c = capacity();
3072 if (__n <= __c && size() <= __c - __n)
3073 {
3074 const_iterator __old_end = end();
3075 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:193076 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:163077 __r = __const_iterator_cast(__position);
3078 }
3079 else
3080 {
3081 vector __v(__alloc());
3082 __v.reserve(__recommend(__size_ + __n));
3083 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:193084 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3085 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:163086 swap(__v);
3087 }
Howard Hinnant0949eed2011-06-30 21:18:193088 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:163089 return __r;
3090}
3091
3092template <class _Allocator>
3093template <class _InputIterator>
3094typename enable_if
3095<
3096 __is_input_iterator <_InputIterator>::value &&
3097 !__is_forward_iterator<_InputIterator>::value,
3098 typename vector<bool, _Allocator>::iterator
3099>::type
3100vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
3101{
3102 difference_type __off = __position - begin();
3103 iterator __p = __const_iterator_cast(__position);
3104 iterator __old_end = end();
3105 for (; size() != capacity() && __first != __last; ++__first)
3106 {
3107 ++this->__size_;
3108 back() = *__first;
3109 }
3110 vector __v(__alloc());
3111 if (__first != __last)
3112 {
3113#ifndef _LIBCPP_NO_EXCEPTIONS
3114 try
3115 {
Howard Hinnant324bb032010-08-22 00:02:433116#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:163117 __v.assign(__first, __last);
3118 difference_type __old_size = static_cast<difference_type>(__old_end - begin());
3119 difference_type __old_p = __p - begin();
3120 reserve(__recommend(size() + __v.size()));
3121 __p = begin() + __old_p;
3122 __old_end = begin() + __old_size;
3123#ifndef _LIBCPP_NO_EXCEPTIONS
3124 }
3125 catch (...)
3126 {
3127 erase(__old_end, end());
3128 throw;
3129 }
Howard Hinnant324bb032010-08-22 00:02:433130#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:163131 }
Howard Hinnant0949eed2011-06-30 21:18:193132 __p = _VSTD::rotate(__p, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:163133 insert(__p, __v.begin(), __v.end());
3134 return begin() + __off;
3135}
3136
3137template <class _Allocator>
3138template <class _ForwardIterator>
3139typename enable_if
3140<
3141 __is_forward_iterator<_ForwardIterator>::value,
3142 typename vector<bool, _Allocator>::iterator
3143>::type
3144vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
3145{
Eric Fiseliera2cd2702016-12-11 05:31:003146 const difference_type __n_signed = _VSTD::distance(__first, __last);
3147 _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified");
3148 const size_type __n = static_cast<size_type>(__n_signed);
Howard Hinnantbc8d3f92010-05-11 19:42:163149 iterator __r;
3150 size_type __c = capacity();
3151 if (__n <= __c && size() <= __c - __n)
3152 {
3153 const_iterator __old_end = end();
3154 __size_ += __n;
Howard Hinnant0949eed2011-06-30 21:18:193155 _VSTD::copy_backward(__position, __old_end, end());
Howard Hinnantbc8d3f92010-05-11 19:42:163156 __r = __const_iterator_cast(__position);
3157 }
3158 else
3159 {
3160 vector __v(__alloc());
3161 __v.reserve(__recommend(__size_ + __n));
3162 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:193163 __r = _VSTD::copy(cbegin(), __position, __v.begin());
3164 _VSTD::copy_backward(__position, cend(), __v.end());
Howard Hinnantbc8d3f92010-05-11 19:42:163165 swap(__v);
3166 }
Howard Hinnant0949eed2011-06-30 21:18:193167 _VSTD::copy(__first, __last, __r);
Howard Hinnantbc8d3f92010-05-11 19:42:163168 return __r;
3169}
3170
3171template <class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003172inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163173typename vector<bool, _Allocator>::iterator
3174vector<bool, _Allocator>::erase(const_iterator __position)
3175{
3176 iterator __r = __const_iterator_cast(__position);
Howard Hinnant0949eed2011-06-30 21:18:193177 _VSTD::copy(__position + 1, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:163178 --__size_;
3179 return __r;
3180}
3181
3182template <class _Allocator>
3183typename vector<bool, _Allocator>::iterator
3184vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
3185{
3186 iterator __r = __const_iterator_cast(__first);
3187 difference_type __d = __last - __first;
Howard Hinnant0949eed2011-06-30 21:18:193188 _VSTD::copy(__last, this->cend(), __r);
Howard Hinnantbc8d3f92010-05-11 19:42:163189 __size_ -= __d;
3190 return __r;
3191}
3192
3193template <class _Allocator>
3194void
3195vector<bool, _Allocator>::swap(vector& __x)
Marshall Clow7d914d12015-07-13 20:04:563196#if _LIBCPP_STD_VER >= 14
3197 _NOEXCEPT
3198#else
Eric Fiselierfb342382016-12-28 06:06:093199 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:563200 __is_nothrow_swappable<allocator_type>::value)
3201#endif
Howard Hinnantbc8d3f92010-05-11 19:42:163202{
Howard Hinnant0949eed2011-06-30 21:18:193203 _VSTD::swap(this->__begin_, __x.__begin_);
3204 _VSTD::swap(this->__size_, __x.__size_);
3205 _VSTD::swap(this->__cap(), __x.__cap());
Marshall Clow7d914d12015-07-13 20:04:563206 __swap_allocator(this->__alloc(), __x.__alloc(),
3207 integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
Howard Hinnantbc8d3f92010-05-11 19:42:163208}
3209
Howard Hinnant324bb032010-08-22 00:02:433210template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:163211void
3212vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
3213{
3214 size_type __cs = size();
3215 if (__cs < __sz)
3216 {
3217 iterator __r;
3218 size_type __c = capacity();
3219 size_type __n = __sz - __cs;
3220 if (__n <= __c && __cs <= __c - __n)
3221 {
3222 __r = end();
3223 __size_ += __n;
3224 }
3225 else
3226 {
3227 vector __v(__alloc());
3228 __v.reserve(__recommend(__size_ + __n));
3229 __v.__size_ = __size_ + __n;
Howard Hinnant0949eed2011-06-30 21:18:193230 __r = _VSTD::copy(cbegin(), cend(), __v.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:163231 swap(__v);
3232 }
Howard Hinnant0949eed2011-06-30 21:18:193233 _VSTD::fill_n(__r, __n, __x);
Howard Hinnantbc8d3f92010-05-11 19:42:163234 }
3235 else
3236 __size_ = __sz;
3237}
3238
Howard Hinnant324bb032010-08-22 00:02:433239template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:163240void
Howard Hinnantd1d27a42011-06-03 19:40:403241vector<bool, _Allocator>::flip() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163242{
3243 // do middle whole words
3244 size_type __n = __size_;
3245 __storage_pointer __p = __begin_;
3246 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3247 *__p = ~*__p;
3248 // do last partial word
3249 if (__n > 0)
3250 {
3251 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3252 __storage_type __b = *__p & __m;
3253 *__p &= ~__m;
3254 *__p |= ~__b & __m;
3255 }
3256}
3257
Howard Hinnant324bb032010-08-22 00:02:433258template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:163259bool
3260vector<bool, _Allocator>::__invariants() const
3261{
Howard Hinnant2c39cbe2013-06-27 19:35:323262 if (this->__begin_ == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:163263 {
3264 if (this->__size_ != 0 || this->__cap() != 0)
3265 return false;
3266 }
3267 else
3268 {
3269 if (this->__cap() == 0)
3270 return false;
3271 if (this->__size_ > this->capacity())
3272 return false;
3273 }
3274 return true;
3275}
3276
Howard Hinnant324bb032010-08-22 00:02:433277template <class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:163278size_t
Howard Hinnantd1d27a42011-06-03 19:40:403279vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163280{
3281 size_t __h = 0;
3282 // do middle whole words
3283 size_type __n = __size_;
3284 __storage_pointer __p = __begin_;
3285 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3286 __h ^= *__p;
3287 // do last partial word
3288 if (__n > 0)
3289 {
3290 const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3291 __h ^= *__p & __m;
3292 }
3293 return __h;
3294}
3295
3296template <class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:003297struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:163298 : public unary_function<vector<bool, _Allocator>, size_t>
3299{
Howard Hinnantee6ccd02010-09-23 18:58:283300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantd1d27a42011-06-03 19:40:403301 size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:163302 {return __vec.__hash_code();}
3303};
3304
3305template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003306inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163307bool
3308operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3309{
3310 const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
Howard Hinnant0949eed2011-06-30 21:18:193311 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:163312}
3313
3314template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003315inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163316bool
3317operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3318{
3319 return !(__x == __y);
3320}
3321
3322template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003323inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163324bool
3325operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3326{
Howard Hinnant0949eed2011-06-30 21:18:193327 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:163328}
3329
3330template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163332bool
3333operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3334{
3335 return __y < __x;
3336}
3337
3338template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003339inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163340bool
3341operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3342{
3343 return !(__x < __y);
3344}
3345
3346template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003347inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163348bool
3349operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3350{
3351 return !(__y < __x);
3352}
3353
3354template <class _Tp, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:003355inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:163356void
3357swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
Howard Hinnantd1d27a42011-06-03 19:40:403358 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:163359{
3360 __x.swap(__y);
3361}
3362
3363_LIBCPP_END_NAMESPACE_STD
3364
3365#endif // _LIBCPP_VECTOR